<div id="test"></div>
<script>
$(document).ready(function() {
alert($('#test').id);
});
</script>
Why doesn’t the above work, and how should I do this?
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
The jQuery way:
In your example:
Expand snippet
Or through the DOM:
or even :
and reason behind usage of
$('#test').get(0)
in JQuery or even$('#test')[0]
is that$('#test')
is a JQuery selector and returns an array() of results not a single element by its default functionalityan alternative for DOM selector in jquery is
which is different from
.attr()
and$('#test').prop('foo')
grabs the specified DOMfoo
property, while$('#test').attr('foo')
grabs the specified HTMLfoo
attribute and you can find more details about differences here.