jquery get attribute value – How to get HTML attribute values in JQuery?

jquery get attribute value – The jQuery attr() method is used to get attribute values. The attr() method sets or returns attributes and values of the selected elements.

jquery: get value of custom attribute

$("input[placeholder]").val($("input[placeholder]").attr("placeholder"));

jquery get attribute value

The name of the attribute to get. simple The .attr() method retrives the attribute value for only the first html element in the matched data set.

get attribute value jquery

var some_var = $( some_jquery_selector ).attr( 'some_attribute_name' );

How to get HTML attribute values in JQuery?

index.html

<html>
<head>
<title>jQuery get attribute example - www.pakainfo.com</title>
   <script type="text/javascript" 
   src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
   
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      var title = $("em").attr("title");
	  alert(title);
      $("#pakanew").text(title);
   });

   </script>
</head>
<body>
   <div>
      <em title="Welcome To Pakainfo.com">Simple jQuery get attributes</em>
      <p id="myid">getting my title attribute- success.</p>
      <div id="pakanew"></div>
   </div>
</body>
</html>

how to get attribute value in jquery

Example

/* html source code */
<a data-id="98255">link</a>

/* js */
$(this).attr("data-id") // returns string "98255"

$(this).data("id") // returns number 98255 (jQuery >= 1.4.3 only)

jQuery Set Attribute

index.html

<html>
<head>
<title>jQuery set attribute example - www.pakainfo.com</title>
   <script type="text/javascript" 
   src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
   <script type="text/javascript" language="javascript">

   $(document).ready(function() {
      $("#pakanew").attr("alt", "Setting New Image");
   });

   </script>
</head>
<body>
   <div>
      <img id="pakanew" src="welcome.png" alt="Welcome New Pakainfo" />
   </div>
</body>
</html>

How to get attribute value in javascript?

I hope you get an idea about jquery get attribute value.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.