Wednesday, 7 August 2013

Can't get the text value of a detached element jQuery

Can't get the text value of a detached element jQuery

I have the following HTML code:
<p id="1">Hello there.</p>
<p id="2">To be removed.</p>
However, I am detaching the <p id="2"> element and it disappears as it
should. However, I can't retrieve the text value inside that <p> element
after the jQuery detach() function is called on it. The jQuery code is as
follows:
$(document).ready(function() {
var p = $('#2').detach();
alert($('#2').val());
});
I can't get the text value to appear in the alert box. Could anyone please
help me out. Thank you.

No comments:

Post a Comment