Is there a direct way to change class of currently selected li elements? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is there a direct way to change class of currently selected li elements?

Is there a direct way to change class of currently selected li elements?

11th Feb 2018, 10:54 AM
ISHTIAQUE BIN IDREES
ISHTIAQUE BIN IDREES - avatar
4 Answers
+ 4
e.target.classList.add("className"); or this.classList.add("className"); you can use this or e.target to select current element.
16th Feb 2018, 2:04 AM
Amrendra Kumar
Amrendra Kumar - avatar
+ 2
var element = document.getElementById("myDIV"); element.classList.add("mystyle"); This is from w3schools.com
16th Feb 2018, 1:52 AM
Jakeb Barnett
Jakeb Barnett - avatar
+ 1
thanks for answering. 😁
16th Feb 2018, 2:45 AM
ISHTIAQUE BIN IDREES
ISHTIAQUE BIN IDREES - avatar
+ 1
$( "li a" ).click(function( event ) { $('#host_panel').empty(); $('a').removeClass() $('a').addClass('nav_anchor'); $(this).addClass('changed_anch') }); I did it in this way.
17th Feb 2018, 8:03 PM
ISHTIAQUE BIN IDREES
ISHTIAQUE BIN IDREES - avatar