jQuery Examples - $("p:last").hasClass("selected")
Description
This would return true if last <p> tag has associated class selected.
Syntax
Here is the simple syntax to use this method −
selector.hasClass("classname");
Parameters
Here is the description of all the parameters used by this method −
classname This is the CSS class of the matched element.
Example
Following example returns true if last <p> tag has associated classselected.
Live Demo
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$("#result1").text( $("p:last").hasClass("selected") );
});
</script>
<style>
.red { color:red; }
.green { color:green; }
</style>
</head>
<body>
<p class="red" id = "pid1">This is first paragraph.</p>
<p class="selected" id = "pid2">This is second paragraph.</p>
<div id = "result1"></div>
</body>
</html>
This will produce following result −
jqueryexamples_attributes.htm
Advertisements