I want to repeat something inside a div tag using javascript to sho...">

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.

+4
source share
3 answers

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.

+5
source

Using jQuery:

$('.content').attr('something','');
+1

, , 960

if ( window.innerWidth > 960 ) {

    document.querySelector('.content').setAttribute('something','')

}
+1

Source: https://habr.com/ru/post/1664146/


All Articles