Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add text to span jQuery

I have this jQuery code that I am using to create a dynamic menu

function createList(test){
      alert(test);
        $('#nav')
        .append('<li class="top"><a href="nogo2" id="products" class="top_link"><span class="down"></span></a></li>');
        $('.down').text(test);
    }

the problem that I have is when I try to add the text to the span

$('.down').text(test);

the menu changes to whatever value is the last for example if my values are a b c d e then all my menus e e e e e can any body help me thanks

like image 403
user1766952 Avatar asked Dec 04 '25 10:12

user1766952


2 Answers

You can try using this to select only the last .down instead of all:

$('.down:last').text(test);
like image 73
Kalecser Avatar answered Dec 07 '25 01:12

Kalecser


Why don't you do it directly like this:

 function createList(test) {
     alert(test);
     $('#nav')
         .append('<li class="top"><a href="nogo2" id="products" class="top_link"><span class="down">' + test + '</span></a></li>');
 }
like image 33
palaѕн Avatar answered Dec 06 '25 23:12

palaѕн



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!