"using name attribute"
Bootstrap 4.0.0 Snippet by lavan

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!DOCTYPE html> <html> <body> <style> .blue{ background:red; } </style> <h2>My First JavaScript</h2> <div onclick="lav(this)" name="division" id="one">1</div> <div id="two" name="division" onclick="lav(this)">2</div> <div id="three" name="division" onclick="lav(this)">3</div> <script> function lav(ths){ var alldiv=document.getElementsByName('division'); for(var i=0;i<alldiv.length;i++){ alldiv[i].className='' } ths.className='blue'; } </script> </body> </html>

Related: See More


Questions / Comments: