Tutorials Point

  jQuery Tutorial
  jQuery UI
  jQuery References
  jQuery Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

jQuery - CSS Element ID Selector

previous next AddThis Social Bookmark Button



The element ID selector selects a single element with the given id attribute.


Here is the simple syntax to use this selector:



Here is the description of all the parameters used by this selector:

  • elementid: This would be an element ID. If the id contains any special characters like periods or colons you have to escape those characters with backslashes.


Like any other jQuery selector, this selector also returns an array filled with the found element.


  • $('#myid') selects a single element with the given id myid.

  • $('div#yourid') selects a single division with the given id yourid.

Following example would select second division and display its content:

<title>The Selecter Example</title>
<script type="text/javascript" src="/jquery/jquery-1.3.2.min.js">
<script type="text/javascript" language="javascript">

   $(document).ready(function() {
      var divs = $("#divid2");
      alert("Found Division: " + divs[0].innerHTML);


<div class="div1" id="divid1">
  <p class="para1" id="pid1">This is first paragraph.</p>
  <p class="para2" id="pid2">This is second paragraph.</p>
  <p class="para3" id="pid3">This is third paragraph.</p>
<br />

<div class="div2" id="divid2">
  <p>This is second division of the DOM.</p>
<br />

<div class="div3" id="divid3">
  <p>This is a para inside third division</p>


To understand it in better way you can Try it yourself.

previous next Printer Friendly