How to add CSS class dynamically to html element

Michael

I am new to JavaScript and especially to AngularJS so maybe my question will seem naive to some.

I am working on my AngularJS tutorial project.

I have this HTML rows:

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="http://acornejo.github.io/bootstrap-nav-wizard/bootstrap-nav-wizard.css" rel="stylesheet"/>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container">
  <ul class="nav nav-wizard">
    <li class="active"><a href="#">Step1</a></li>
    <li><a href="#">Step2</a></li>
    <li><a href="#">Step3</a></li>
  </ul>
  <hr>
</div>
</body>

When I press on <a> tag I need to make it active (i.e. to set attribute class of the <li> element to active as it showed in step1).

How can I implement it programmatically in client side?

bobleujr

Michael,

if you are using angular, you should use <li ng-class="'yourclass': expression">

ngClass documentation

Check out this Codepen

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add CSS class to the HTML5 picture element

From Dev

How to add a class to an element with CSS

From Dev

How to dynamically add HTML element/content - Angular

From Dev

How to add | remove css class in angular element?

From Dev

Add class to dynamically added element

From Dev

How to add class to html element with Deface?

From Dev

OM how to add class to html element

From Dev

How to add html class to above element

From Dev

How to add onclick to a html element dynamically using javascript

From Dev

How to create input element with div class dynamically in html table?

From Dev

How to add css class to an element inside nav element

From Dev

How to add or apply a CSS class to an entire HTML

From Java

Thymeleaf: how to use conditionals to dynamically add/remove a CSS class

From Dev

css add class to selected element

From Dev

jQuery: Dynamically add class that belongs to another element

From Dev

How to add a dynamic css class inside a html class attribute in angularjs?

From Dev

Maximo Anywhere - Dynamically changing CSS class of element

From Dev

How to add class CSS after ng-click to parent element?

From Dev

How Do I Add CSS Class to body Element in Meteor?

From Dev

How to dynamically add methods to a class?

From Dev

Add multiple html element dynamically using jquery

From Dev

How to add class to html element in django-bootstrap3 template

From Dev

How to add HTML class based on the contents of another element?

From Dev

jQuery add CSS Class to bootbox Modal Dynamically

From Dev

angularjs dynamically set css on html element

From Dev

Adding css classes to html element dynamically in php

From Dev

How to put css class in to html:select element in jsp

From Dev

How to apply a bootstrap class to every same HTML element in css file?

From Dev

jQuery - How to add css to a parent element if child element has certain css class

Related Related

  1. 1

    How to add CSS class to the HTML5 picture element

  2. 2

    How to add a class to an element with CSS

  3. 3

    How to dynamically add HTML element/content - Angular

  4. 4

    How to add | remove css class in angular element?

  5. 5

    Add class to dynamically added element

  6. 6

    How to add class to html element with Deface?

  7. 7

    OM how to add class to html element

  8. 8

    How to add html class to above element

  9. 9

    How to add onclick to a html element dynamically using javascript

  10. 10

    How to create input element with div class dynamically in html table?

  11. 11

    How to add css class to an element inside nav element

  12. 12

    How to add or apply a CSS class to an entire HTML

  13. 13

    Thymeleaf: how to use conditionals to dynamically add/remove a CSS class

  14. 14

    css add class to selected element

  15. 15

    jQuery: Dynamically add class that belongs to another element

  16. 16

    How to add a dynamic css class inside a html class attribute in angularjs?

  17. 17

    Maximo Anywhere - Dynamically changing CSS class of element

  18. 18

    How to add class CSS after ng-click to parent element?

  19. 19

    How Do I Add CSS Class to body Element in Meteor?

  20. 20

    How to dynamically add methods to a class?

  21. 21

    Add multiple html element dynamically using jquery

  22. 22

    How to add class to html element in django-bootstrap3 template

  23. 23

    How to add HTML class based on the contents of another element?

  24. 24

    jQuery add CSS Class to bootbox Modal Dynamically

  25. 25

    angularjs dynamically set css on html element

  26. 26

    Adding css classes to html element dynamically in php

  27. 27

    How to put css class in to html:select element in jsp

  28. 28

    How to apply a bootstrap class to every same HTML element in css file?

  29. 29

    jQuery - How to add css to a parent element if child element has certain css class

HotTag

Archive