Welcome to WebmasterWorld Guest from 54.211.86.24

Forum Moderators: open

selector not working

   
10:45 pm on Apr 10, 2011 (gmt 0)

5+ Year Member



Hopefully, the last problem for a while: the function below is supposed to select a span which is the child of a class and add some text to the span.

The html looks like this:
<p class="a1">some text<span></span></p>
The class is a variable... 'a1' 'a2' etc.

function addTxt(myline) {
$(myline > span).html(' more text ');
}

called with addTxt('.a1').

Firefox is giving the error message 'span is undefined'.
There may be a clue here: if it's changed to

$(p.myline > span).html(' more text ');

the error message changes to 'p is undefined'.

I could give the spans a class, but that would make the code heavier as there are hundreds of em.

Any ideas?
10:59 pm on Apr 10, 2011 (gmt 0)



selector should be a string, you're passing '.a1' as a string, so you need to concatenate to get the complete string:

$(myline+' > span').html(' more text');

HTH

--
Milan B.

[edited by: engine at 1:58 pm (utc) on Apr 15, 2011]
[edit reason] no sig files, thanks [/edit]

1:45 am on Apr 11, 2011 (gmt 0)

5+ Year Member



Milan, it sure did!
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved