jquerry attr code example
Example 1: jQuery - Get Content and Attributes
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
});
</script>
</head>
<body>
<p id="test">This is some <b>bold</b> text in a paragraph.</p>
<button id="btn1">Show Text</button>
<button id="btn2">Show HTML</button>
</body>
</html>
Example 2: jquery attr
$( some_item ).attr( "id", "some-id" );
$( some_item ).attr({
id: "some-id",
title: "Opens in a new window",
"data-value": "internal link"
});