We can easily access the attributes of HTML tags and we can easily modified the attributes of HTML tags using the jQuery attr() function.
$("TagSelector").attr("attributeName");
For assigning the attribute value.
$("TagSelector").attr("attributeName","Attribute value");
We are considering two examples , example to fetch the tag attribute value and example to assign the value to the attribute of tag.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button> Get image Width </button>
<img width='500' src='https://codingpk.com/images/CodingPk-Logo.png' />
<script type="text/javascript">
$("button").click(function()
{
var width = $("img").attr("width");
alert(width);
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button> Set image Width 600 px </button>
<img width='500' src='https://codingpk.com/images/CodingPk-Logo.png' />
<script type="text/javascript">
$("button").click(function()
{
$("img").attr("width","600");
});
</script>
$("img").attr({ "width":"600","border":"10" });