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.


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

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



Access HTML elements by id attribute.

Example 1

<!DOCTYPE html>
		<title>Access ID</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript" src="jquery.min.js">
                                // get <p> element and has the id=man
				$("p#man").html("A great leader!");
				$("p#woman").html("A great mother");
         <p id="man">Great man!</p>
         <p id="woman">Great woman!</p>

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