Solved

error in jquery and javascript

Posted on 2014-02-20
2
254 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

685 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