views:

220

answers:

4

Hi Guys,

I am new to javascript and still learning the ropes. I am trying to use addClass to a subclass

I assumed that this would work:

jQuery('#wrow .text').addClass("error"); 
jQuery('#wrow .text').removeClass("error");

But it doesn't ? Little unsure how to do this to subclasses ? I am sure you gurus will help in a jiffy! :)

Edit: I am actually using

jQuery('#wrow_' + nameSpace + '.text').addClass("error");

but it isn't working?

A: 

Perhaps describe a little bit more as to what you're trying to accomplish?

$('#wrow .text').addClass("error"); 
$('#wrow .text').removeClass("error");

Will take any descendent of #wrow with the .text class and add the error class to those elements.

If you want to find the #wrow element when it also has the class "text", then it should look like this:

$('#wrow.text').addClass("error"); // no space in the selector

I don't think that's what you want either because you'd really only have one #wrow in the page (if you have more, you have another problem as IDs are supposed to be unique) so please clarify.

Michael Haren
hey :) thanks for the response - yeah i am actually doingjQuery('#wrow' + nameSpace + '.text').addClass("error"); but it aint working ?
Post your html, please
Michael Haren
A: 

how does your html looks like. I'm just guessing that .text is child element of #wrow?

jQuery('#wrow > .text').addClass("error"); 
jQuery('#wrow > .text').removeClass("error");
stefita
+3  A: 

If this is your actual code

jQuery('#wrow_' + nameSpace + '.text').addClass("error");

Then I suspect you're missing a space

jQuery('#wrow_' + nameSpace + ' .text').addClass("error");
// put a space right here -----^
Peter Bailey
A: 
jQuery('#wrow_' + nameSpace + '.text').addClass("error");

What is nameSpace? Will it actually contain a space? If not you may need a space on one or both sides

Andrew G. Johnson