Let's say I've a few
<p> Hello </p>
<p> Hello </p>
<p> Hello </p>
<p> Hello </p>
I want to replace one "Hello" by "Good bye".
So => $('p')[2].html('Good Bye');
It is not working why? Why should I must use the eq: selector?
It's working when I do that
$('p:eq(3)').html('Good bye')
You are trying to use html()
method with javascript object
which is supposed to be used with jQuery object, you can use innerHTML
with javascript object so you need this,
Live Demo
$('p')[2].innerHTML = 'Good Bye';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With