Welcome to WebmasterWorld Guest from 54.226.27.104

Forum Moderators: open

Message Too Old, No Replies

selector not working

     

ctoz

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?

mbabuskov

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]

ctoz

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

5+ Year Member



Milan, it sure did!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month