Get first element in query set in jQuery
Description
The following code shows how to get first element in query set.
Example
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from w ww . j a v a 2 s . c o m-->
var mappedItems = $("li").map(function (index) {
var data = $("<li>").text($(this).text()).get(0);
data = [data,$("<li>").get(0)];
$(data[0]).append("*");
return data;
});
$("#results").append(mappedItems);
});
</script>
</head>
<body>
<body>
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
<ul id="results">
</ul>
</body>
</html>
The code above generates the following result.
...
Create a custom selector that selects eleme...
Escape characters in selector in jQuery
Escape the dot and [] in selector in jQuery
Filter by class name in jQuery
Filter by id returned from a function in jQ...
Filter class out for a list of selected ele...
Filter content by node type in jQuery
Filter contents of a paragraph by node type...
Filter element by checking class existance ...
Filter element by index in jQuery
Filter element list by index in jQuery
Filter out element and add style in jQuery
Filter parent with class in jQuery
Filter selected element list by ID in jQuer...
Filter with customized function in jQuery
Find all children with a class "selected" o...
Find radio button within the first form in ...
Get all form elements in different ways in ...
Get parent for a form input element in jQue...
Get the count of input elements in jQuery
Get the last span just added to a paragraph...
Get the length for matched element list in ...
Get the tag name of the element clicked on ...
Map parent elements to get all their names ...
Mark under line by content $("div:contains(...
Match all elements including head, body, et...
Match input element with attribute-begin-wi...
Reference current element its event handler...
Remove an element by its contents $("p") in...
Select Form Checkbox with Form Checkbox sel...
Select Form Checked box $("input:checked") ...
Select Form Disabled form element $("input:...
Select Form Enabled form element $("input:e...
Select Form File upload $(":file") in jQuer...
Select Form Image button with Form Image bu...
Select Form Password field with Form Passwo...
...
Create a custom selector that selects eleme...
Escape characters in selector in jQuery
Escape the dot and [] in selector in jQuery
Filter by class name in jQuery
Filter by id returned from a function in jQ...
Filter class out for a list of selected ele...
Filter content by node type in jQuery
Filter contents of a paragraph by node type...
Filter element by checking class existance ...
Filter element by index in jQuery
Filter element list by index in jQuery
Filter out element and add style in jQuery
Filter parent with class in jQuery
Filter selected element list by ID in jQuer...
Filter with customized function in jQuery
Find all children with a class "selected" o...
Find radio button within the first form in ...
Get all form elements in different ways in ...
Get first element in query set in jQuery
Get list item index in jQueryGet parent for a form input element in jQue...
Get the count of input elements in jQuery
Get the last span just added to a paragraph...
Get the length for matched element list in ...
Get the tag name of the element clicked on ...
Map parent elements to get all their names ...
Mark under line by content $("div:contains(...
Match all elements including head, body, et...
Match input element with attribute-begin-wi...
Reference current element its event handler...
Remove an element by its contents $("p") in...
Select Form Checkbox with Form Checkbox sel...
Select Form Checked box $("input:checked") ...
Select Form Disabled form element $("input:...
Select Form Enabled form element $("input:e...
Select Form File upload $(":file") in jQuer...
Select Form Image button with Form Image bu...
Select Form Password field with Form Passwo...
...