Jump to: navigation, search

JQuery Access Class Attribute

From w3cyberlearnings

Contents

jQuery Access HTML elements by class attribute

jQuery uses to retrieve content from 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.

Syntax

Access the class attributes.

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

Note

Access HTML elements by the ID attribute.

Example TRY-IT

<!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>

Related Links


Navigation
Web
SQL
MISC
References