Reputation: 299
what is the real difference between the following code:
<p>Maizere1</p>
<p>Maizere2</p>
<p>Maizere3</p>
<script>
$("p").text($(this).text()).get(0);
vs
$("<p>").text($(this).text()).get(0);//actually this line is what giving me trouble
what does $("<p>"> this do?
i heard that $("<p>") will first actually check where the element exist or not ,if not only will create element
Upvotes: 0
Views: 55
Reputation: 5152
$("<p>")
creats a new element and you can use .append()
to add it to the dom while $("p")
selects them.
correct is to use $("<p>")
like this: $("<p />")
. But jQuery allows both.
Example:
<p></p>
$("p").append($("<p>test</p>").addCLass("test"));
result:
<p class="test">
<p>test</p>
</p>
Upvotes: 2