Set div tag attribute
I have a simple code
<div class="content"></div>
I want to repeat something inside a div tag using javascript to show this path
<div class="content" something></div>
I need this with javascript because I want to use the function for echo if the screen is wider than 960 pixels I used this answer for the second part Do something if the screen width is less than 960 pixels
Thanks to the guy in advance.
What is called attribute, you can use the following methods to set the attribute.
Pure JS method: setAttribute()
element.setAttribute('name','value');
jQuery method: attr()
$(element).attr('name','value');
Example:
document.querySelector('.content').setAttribute('something',''); //Pure JS
//Or
$('.content').attr('something',''); //jQuery
Hope this helps.