Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
166
rated 0 times [  167] [ 1]  / answers: 1 / hits: 15214  / 8 Years ago, mon, december 19, 2016, 12:00:00

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.


More From » jquery

 Answers
31

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.


[#59656] Friday, December 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;