how to select class selector in Javascript

Something Like that:
querySelector()

For that you need to create first html code.

HTML

<p class="img-1">Home2it</p>

After that add this JS code.

JS

var img1 = document.querySelector('.img-1');
console.log(img1);

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”mByXJo” default_tab=”js,result” user=”pradeepanvi”]See the Pen how to select class selector in Javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

You can check console.

Leave a Reply

Your email address will not be published. Required fields are marked *