Skip to main content
Question Protected by Sheldore
added script tag
Source Link
Yann Chabot
  • 4.9k
  • 3
  • 43
  • 59
<div id="test"></div>
<script>
  $(document).ready(function() {
    alert($('#test').id);
  });  
</script>

Why doesn't the above work, and how should I do this?

<div id="test"></div>

$(document).ready(function() {
    alert($('#test').id);
});  

Why doesn't the above work, and how should I do this?

<div id="test"></div>
<script>
  $(document).ready(function() {
    alert($('#test').id);
  });  
</script>

Why doesn't the above work, and how should I do this?

Put it in the form of a question and made the details a little more readable.
Source Link

Getting How can I get the IdID of a jQueryan element using jQuery?

<div id="test"></div>

$(document).ready(function() {
    alert($('#test').id);
});  

Can someone please explain to me whyWhy doesn't the above doesn't work, and tell me how should I can get the ID of a jQuery element that has been passed into a function.do this?

Getting the Id of a jQuery element

<div id="test"></div>

$(document).ready(function() {
    alert($('#test').id);
});  

Can someone please explain to me why the above doesn't work, and tell me how I can get the ID of a jQuery element that has been passed into a function.

How can I get the ID of an element using jQuery?

<div id="test"></div>

$(document).ready(function() {
    alert($('#test').id);
});  

Why doesn't the above work, and how should I do this?

Source Link
fearofawhackplanet
  • 53.6k
  • 55
  • 166
  • 258

Getting the Id of a jQuery element

<div id="test"></div>

$(document).ready(function() {
    alert($('#test').id);
});  

Can someone please explain to me why the above doesn't work, and tell me how I can get the ID of a jQuery element that has been passed into a function.