Set An Attribute To The Div Tag
I have a simple code I want to echo something inside the div tag using javascript to show this way
&l
Solution 1:
That called attribute
, to set attribute you could use the methods below.
Pure JS setAttribute()
method :
element.setAttribute('name','value');
jQuery attr()
method :
$(element).attr('name','value');
Example :
document.querySelector('.content').setAttribute('something',''); //Pure JS//Or
$('.content').attr('something',''); //jQuery
Hope this helps.
Solution 2:
With jQuery:
$('.content').attr('something','');
Solution 3:
If you want to add the attribute if window width is greater then 960
if ( window.innerWidth > 960 ) {
document.querySelector('.content').setAttribute('something','')
}
Post a Comment for "Set An Attribute To The Div Tag"