$(function() { var txt = $("<p></p>").text("Hi"); $("#demo").after(txt); }); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

$(function() { var txt = $("<p></p>").text("Hi"); $("#demo").after(txt); });

i want "Hi" to appear 2 times , but by repeating the same query twice i am not getting the result, so should i declare a new variable to store the same value or is there any other method? Also what should i do if i want to create 2 'p' tags with different id , using jquery

9th Sep 2018, 12:34 PM
AVHIJIT NAIR
AVHIJIT NAIR - avatar
1 Answer
+ 2
I wouldn't repeat the query, I would call the function twice from the applicable section in the HTML. The answer to the second question sort of depends on what the purpose of doing that would be and what you want the id's to end up looking like (what you're planning on naming them). Maybe there would be a better choice.
9th Sep 2018, 2:06 PM
Janning⭐
Janning⭐ - avatar