JQuery Access Id Attribute

From CoderLearner
Jump to: navigation, search

jQuery Access HTML elements by Id attribute

The id attribute is a unique identifier for HTML element. You can assign or retrieve the HTML element by using the id attribute.

Syntax

#c355, #c3ff, and #fccc is the example of the id attribute.

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

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

Note

Access HTML elements by id attribute.

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($("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>

<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"/>