Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector does not work?

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')
like image 344
Meds Avatar asked Jan 14 '23 21:01

Meds


1 Answers

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';
like image 127
Adil Avatar answered Jan 25 '23 02:01

Adil