Select elements with id attribute in jQuery
Description
The following code shows how to select elements with id attribute.
Example
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- w ww. jav a2s . c o m-->
$("div[id]").one("click", function(){
var idString = $(this).text() + " = " + $(this).attr("id");
$(this).text(idString);
});
});
</script>
</head>
<body>
Click to see.
<div>div</div>
<div id="hey">div</div>
</body>
</html>
The code above generates the following result.
...
Select all elements that are the last child...
Select all elements that are the nth-child ...
Select all elements that are the only child...
Select all elements under a certain element...
Select all p elements inside a div in jQuer...
Select all previous tags and set styles in ...
Select all the divs before the last and giv...
Select an element by element name and its i...
Select based on text content with Contains ...
Select by check child element with has meth...
Select current and next element in jQuery
Select current element with $(this) selecto...
Select div element with paragraph inside $(...
Select div parent elements of each span in ...
Select element by Combining first selector ...
Select element by checking if if the specif...
Select element by class name in jQuery
Select elements by tag name $("div") in jQu...
Select even numbered child in jQuery
Select event table row with Even element se...
Select first paragraph with first selector ...
Select first paragraph with given class in ...
Select for Odd table row with odd element s...
Select for nested classes with .myClass.myO...
Select input element by
Select input element by name attribute in j...
Select input element that don't have the na...
Select last paragraph in jQuery
Select not checked form input elements in j...
Select numbered child in jQuery
Select odd numbered child in jQuery
Select paragraph at even position and remov...
Select parent with parent selector $("td:pa...
Select sibling for checked form elements $(...
Select sibling with General sibling $('E ~ ...
Select tag first parent in jQuery
...
Select all elements that are the last child...
Select all elements that are the nth-child ...
Select all elements that are the only child...
Select all elements under a certain element...
Select all p elements inside a div in jQuer...
Select all previous tags and set styles in ...
Select all the divs before the last and giv...
Select an element by element name and its i...
Select based on text content with Contains ...
Select by check child element with has meth...
Select current and next element in jQuery
Select current element with $(this) selecto...
Select div element with paragraph inside $(...
Select div parent elements of each span in ...
Select element by Combining first selector ...
Select element by checking if if the specif...
Select element by class name in jQuery
Select elements by tag name $("div") in jQu...
Select elements with id attribute in jQuery
Select empty table cell in jQuerySelect even numbered child in jQuery
Select event table row with Even element se...
Select first paragraph with first selector ...
Select first paragraph with given class in ...
Select for Odd table row with odd element s...
Select for nested classes with .myClass.myO...
Select input element by
name
a...Select input element by name attribute in j...
Select input element that don't have the na...
Select last paragraph in jQuery
Select not checked form input elements in j...
Select numbered child in jQuery
Select odd numbered child in jQuery
Select paragraph at even position and remov...
Select parent with parent selector $("td:pa...
Select sibling for checked form elements $(...
Select sibling with General sibling $('E ~ ...
Select tag first parent in jQuery
...