Get element with certain ID using .is() method - Javascript jQuery Selector

Javascript examples for jQuery Selector:id

Description

Get element with certain ID using .is() method

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-2.1.3.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from   w  w w. jav  a 2  s  . c om
$( document ).ready(function() {
   var id = "foo";
   if($("div").is("#" + id))
      console.log($("div").text());
});
    });

      </script> 
 </head> 
 <body> 
  <div id="foo">
    Some text 
  </div>  
 </body>
</html>

Related Tutorials