homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

selector not working

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

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');


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)

Milan, it sure did!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

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