Solved

error in jquery and javascript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now