Solved

error in jquery and javascript

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

Expert Comment

by:Chris Stanyon
Comment Utility
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 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

744 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

20 Experts available now in Live!

Get 1:1 Help Now