Answers for ".addClass"

89

js add class

var element = document.getElementById('element');
element.classList.add('class-1');
element.classList.add('class-2', 'class-3');
element.classList.remove('class-3');
Posted by: Guest on May-07-2020
8

jquery addclass

$("#elem").addClass("classname");
Posted by: Guest on June-06-2020
31

addclass javascript

var someElement= document.getElementById("myElement");
    someElement.className += " newclass";//add "newclass" to element (space in front is important)
Posted by: Guest on July-24-2019
0

how to add class on the base of has class in jquery

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>addClass demo</title>
  <style>
  p {
    margin: 8px;
    font-size: 16px;
  }
  .selected {
    color: red;
  }
  .highlight {
    background: yellow;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
 
<p>Hello</p>
<p>and</p>
<p>Goodbye</p>
 
<script>
$( "p" ).last().addClass( "selected highlight" );
</script>
 
</body>
</html>
Posted by: Guest on October-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language