0

Why is $("<p></p>").text ("example") used in place of $("p")?

I have been learning JQuery with the app but it never really explains any difference or use for that

31st Dec 2017, 4:42 AM
Lucas Moyano
Lucas Moyano - avatar
3 Respuestas
+ 2
the first selects all p tags,same with second.But the difference is the first can be used to select a p tag with I'd $("<p Id='p' ></p>");
31st Dec 2017, 5:01 AM
᠌᠌Code X
᠌᠌Code X - avatar
0
I am not quite sure, but does the first selector select empty paragraphs, while the second selects all paragraphs, doesn't it? UPDATE: first selector and second are totally equal. My first suggestion is wrong that would be done by $("p:empty"). This means you can use both in the same way. For class or id selection use their specific selectors.
31st Dec 2017, 4:45 AM
Andreas K
Andreas K - avatar
0
Therefore you should use the ID selector $("#id)
31st Dec 2017, 5:36 AM
Andreas K
Andreas K - avatar