Setting text of li
Asked Answered
B

1

16

I have made list:

<ul>
<li id="one"></li>
</ul>

And then in jQuery I do:

 $("#one").text("one");

However it is not changing, also I have tried using .val() but it didn't help.

Why it happens and how to change the li text?

Baklava answered 19/6, 2013 at 11:37 Comment(8)
$("#one").text("one") should work. See your browser console for errorsTruett
can u show the remaining codeNedi
are you waiting for DOM ready? How do you call this code?Magdalen
see here jsfiddle.net/zBxTm it is workingNedi
Works fine : jsfiddle.net/pHKvFDevoice
@roasted, you should post that as an answer because that's likely the problemOrson
@Orson that's ok i felt PSR was on the way to do it ;)Magdalen
@Orson :- PSR is much faster to post that .. :)Somnambulate
N
20

There may be one of the problem you have

1) You did not imported js files properly

2)You might not write the code in ready function

Write your code in ready function and import jQuery related js files.

$( document ).ready(function() {
    $("#one").text("one");
});

http://jsfiddle.net/zBxTm/

Nedi answered 19/6, 2013 at 11:41 Comment(1)
HOw to set text to second item of li.? How to iterate among all childs?Tollmann

© 2022 - 2024 — McMap. All rights reserved.