-3

How to call a bootstrap class into JavaScript using the HTML DOM getElementsByClassName() method?

for eg:-

document.getElementByClass=("has-error");

I need a the text box to turn into green if the data is valid and to red if the data is invalid using Bootstrap classes has-success and has-error.

Gediminas Masaitis
  • 3,172
  • 14
  • 35
balaji
  • 27
  • 6
  • bootstrap is already setting these classes; just use CSS to apply styles – SteamDev Mar 15 '16 at 18:41
  • bootstrap has already written some styles for this class i need to call this styles directly. – balaji Mar 15 '16 at 18:43
  • use CSS to override bootstrap's styles; javascript is not necessary here. include your styles for these classes after `bootstrap.css` in a separate stylesheet. – SteamDev Mar 15 '16 at 18:48
  • i can get you. you are asking me to add a style in css and asking me to call that file into that but in bootstrap there is a class for this function why should i write in seperate css if it there – balaji Mar 15 '16 at 19:05
  • use angular `ng-class` .. see docs – charlietfl Mar 15 '16 at 19:20

1 Answers1

0

See the bootstrap will do this any have I will show you the code based on your example.

function addClassNameListener(elemId, callback) {
    var elem = document.getElementById(elemId);
    var lastClassName = elem.className;
    window.setInterval( function() {   
       var className = elem.className;
        if (className !== lastClassName) {
            callback();   
            lastClassName = className;
        }
    },10);
}

This topic already discussed in event trigger on class change . Working example : http://jsfiddle.net/RaguNS/Lt99puLz/1/

Community
  • 1
  • 1
Ragu N S
  • 17
  • 1
  • 7