How to check if an element exists in jquery

To check a element present in a page we can use .lenght jquery property. If the elements present in a page .lenght property wil return the totel number of matached elements. If the element is not present the page it will return “0″.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script>
$(document).ready(function(){
var a= $('div').length  //this will return 2
var b = $('div#wrap').length // this will return 1
var a= $('p').length  //this will return 0
});
</script>
<body>
<div id="wrap">some text 1</div>
<div> some text 2</div>
</body>
</html>