Jump to: navigation, search

JQuery Access Id Attribute

From w3cyberlearnings

Contents

jQuery Access HTML elements by Id attribute

jQuery uses to retrieve content from or assign content to HTML elements by using id attribute. The id attribute is a unique identifier for HTML element.

Syntax

#c355, #c3ff, and #fccc are the id attribute and its value.

$("p#c355").html("something"); // assign
$("p#c3ff").html(); // get 

$("div#fccc").html();

Note

Access HTML elements by 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($("p#man").html());// get <p> element and has the id=man
				$("p#man").html("A great leader!");
				$("p#woman").html("A great mother");
			});
		</script>
	</head>
	<body>
         <p id="man">Great man!</p>
         <p id="woman">Great woman!</p>
	</body>
</html>

Related Links


Navigation
Web
SQL
MISC
References