jQuery:Selector #id

Overview

Matches the element according to the given ID.

You can use any character(!”#$%&'()*+,./:;<=>?@[\]^`{|}~) as the name text, and it must be escaped by two backslashes:\\ As showed in followed demo.

Parameter

idStringV1.0

Used to search for. The value given by the id attribute of the element.

Demo

Description:

To find the element with ID”myDiv”

HTML code:
<div id="notMe"><p>id="notMe"</p></div>
<div id="myDiv">id="myDiv"</div>
jQuery code:
$("#myDiv");
Result:
[ <div id="myDiv">id="myDiv"</div> ]

Description:

To find the element with special characters.

HTML code:
<span id="foo:bar"></span>
<span id="foo[bar]"></span>
<span id="foo.bar"></span>
jQuery code:
#foo\\[bar\\]
Result:
[ <span id="foo[bar]"></span>]

Leave a Reply

Your email address will not be published. Required fields are marked *