I have an anchor in my HTML. it has a page attribute with a value. So everytime it is clicked I use the page attribute value in my js. Now I want to set a style attribute with a
To select an element by attribute value, you can use this syntax:
$('[attribName="value here"]')
Where attribName
should be replaced with attribute name such as name
, title
, etc.
To add a new attribute value, you can use the attr method.
Example:
$('[attribName="value here"]').attr('attribute name', 'attribute value');
And this is how you can change the background color:
$('[attribName="value here"]').css('background-color', 'green');
Note you should replace dummy attribute names and values as per your requirements.