I have a simple code
<div class="content"></div>
I want to echo something inside the div tag using javascript to show this way
<div class="content" something></div>
I need it using javascript because I want to use a function to echo something if the screen is wider than 960px I used this answer for the second part Do something if screen width is less than 960 px
Thanks guy in advance.
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.
With jQuery:
$('.content').attr('something','');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With