Get the `id` of the element just created - Javascript jQuery Selector

Javascript examples for jQuery Selector:id

Description

Get the `id` of the element just created

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
   </head> 
   <body> 
      <div id="container"></div> 
      <script type="text/javascript">
function createElement(element) {
  var node = $(element);/*from ww w.  j a  v a2  s.c o m*/
  $('#container').append(node);
  console.log(node.attr('id'));
}
createElement('<div id="abc">Some content</div>');

      </script>  
   </body>
</html>

Related Tutorials