Solved

error in jquery and javascript

Posted on 2014-02-20
2
252 Views
Last Modified: 2014-02-21
Hi,

I want to do this, what is wrong? Is there a addClass in javascript that doesn't remove the existing class?

tbl.rows[r].cells.item(c).className = "ty";
var trd = tbl.rows[r].cells.item(c);
$("trd").addClass("vacant");      

the idea is to append a class to the existing one to finish like that

<td class "ty addClass">test</td>
0
Comment
Question by:joyacv2
  • 2
2 Comments
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39876598
You're mixing javascript with jQuery so your code look a bit of a mess, but addClass() won't remove other classes. You don't need the quotes around trd. Try this:

$(trd).addClass("vacant");
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39876621
If you want to add a class in pure Javascript, rather than using jQuery's addClass() method, then something like this:

var trd = tbl.rows[r].cells.item(c);
trd.className += " vacant"; //don't forget the space!

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery delay animation 3 30
How can I repeat this modal box over and over again...? 2 19
JS does not refresh 6 21
Add shadow behind div 5 14
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question