JQuery Access Class Attribute

From CoderLearner
Jump to: navigation, search

jQuery Access HTML elements by class attribute

jQuery retrieve or assign content to HTML elements by using the class attribute. The class attribute specifies the element to be a member of one or more classes. Access the class attribute with the . (dot) and the class attribute name.

  • <p class="dogg">....</p>
$('p.dogg').html();

Syntax

Access the class attributes.

$("div.myclass").html("Great and wonderful");
$('.myclass').css("color","blue");

Example 1

<!DOCTYPE html>
<html>
	<head>
		<title>Access ID</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript" src="jquery.min.js">
		</script>
		<script>
			$(document).ready(function(){
				alert($("div.myclass").html());
				$("div.myclass").html("Great and wonderful");
				$('.myclass').css("color","blue");
			});
		</script>
	</head>
	<body>
                <div class="myclass">Love and love!</div>
		<p class="myclass">Good old day!</p>
	</body>
</html>

<seo metagenerator="jquery tutorial" title="Jquery/Ajax" metakeywords="jquery greater,jquery gt, jquery lt, less then, odd jquery,jquery find element, even jquery,jquery event, jquery mouse click, jquery double click, jquery hover, jquery string, jquery array, jquery button, jquery attriubtes" metadescription="jquery button, jquery attriubte, jquery example, jquery tutorial, jquery sample"/>