Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  190] [ 5]  / answers: 1 / hits: 11321  / 10 Years ago, thu, april 10, 2014, 12:00:00

I have an html element like this:



<dd><span class=label label-success id=status>Production</span></dd>


I want to change it to



<dd><span class=label label-warning id=status>Idle</span>


based on a ws.socket message.



setTimeout(function(){
window.ws = new WebSocket('ws://localhost:8088/sock/123');
window.ws.onmessage = function (evt) {
field.value = Idle
};
window.ws.onclose = function (evt){

}
window.ws.onopen = function (evt){

}

}, 500);


I want to change the value from Production to Idle and the class to label label-warning.
I know to change the value I would do this:



var field = document.getElementById(status)


but I'm not exactly sure how to change the class and would using field.value be the correct way to change a span text?


More From » jquery

 Answers
2

You have jQuery, use it!



$(#status).text(Idle).removeClass(label-success).addClass(label-warning);


Or just .toggleClass(label-success label-warning);


[#46128] Thursday, April 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rashawn

Total Points: 451
Total Questions: 83
Total Answers: 83

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;