Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

error in jquery and javascript

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
joyacv2
Asked:
joyacv2
  • 2
1 Solution
 
Chris StanyonCommented:
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
 
Chris StanyonCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now