I'm new to JQuery and am having trouble getting the content of a div block.
<div class="update_status">
Updated successfully
</div>
And when the following script runs:
$(document).ready(function () {
$(function () {
var $status_div = $("#update_status");
if ($status_div) {
alert("1");
alert($status_div.html());
alert("2");
} else {
alert("undefined");
}
});
});
I receive three alerts, "1", "undefined", and "2". I expected to get "Updated Successfully". Any ideas on what I did wrong?
#
is used to find elements by id
. You are using a class so you need .
$(".update_status");
http://api.jquery.com/category/selectors/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With