27

Вопрос по javascript – Javascript изменить стиль Div

Error: User Rate Limit Exceededpart 1Error: User Rate Limit Exceededpart 2Error: User Rate Limit Exceededpart 2Error: User Rate Limit Exceeded Error: User Rate Limit Exceeded function abc() { document.getElementById("test").style.color="red"; ...

Error: User Rate Limit Exceeded

от Willem D'Haeseleer

7 ответов

41

function abc() {
    var color = document.getElementById("test").style.color;
    if (color === "red")
         document.getElementById("test").style.color="black";
    else
         document.getElementById("test").style.color="red";
}
0

function abc() {
    var color = document.getElementById("test").style.color;
    color = (color=="red") ? "black" : "red" ;
    document.getElementById("test").style.color= color;
}
1

Error: User Rate Limit Exceeded

function abc() {
    var currentColor = document.getElementById("test").style.color;

    if(currentColor == 'red'){
    document.getElementById("test").style.color="black";
    }else{
   document.getElementById("test").style.color="red";

    }
}
0

Error: User Rate Limit Exceeded

function abc() {
    var elem=document.getElementById('test'),color;
    switch(elem.style.color) {
        case('red'):
            color='black';
            break;
        case('black'):
        default:
            color='red';
    }
    elem.style.color=color;
}
0

Error: User Rate Limit Exceeded

function abc(){
  var myDiv = document.getElementById("test");
  if (myDiv.className == 'alert') {
    myDiv.className = 'regular';
  } else {
    myDiv.className = 'alert';
  }
}
2

Error: User Rate Limit Exceeded

$(document).ready(function(){
    $('div').click(function(){
        $(this).toggleClass('clicked');
    });
});​

Error: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

function abc(){
     var color = document.getElementById("test").style.color;
     if(color==''){
         //change
     }else{
         //change back
     }
}

Похожие вопросы