开发者

do not addClass if option is checked

On the website I have a button with an addClass statement. Before this button is clicked there is a possible option to check a radio button. Is it possible to not add the class if the button is checked?

The current code:

Radio button:

<input type="radio" name="test_name" id="test_id" value="0" title="test_title" onclick="$test_click" class="radio" /><label>radio text</label>

Button:

<button type开发者_StackOverflow="button" title="button_test" class="button" onclick="addClass();"> button text</button>

addClass statement (working):

<script type="text/javascript">
function addClass() {
$j('.test').addClass('test2');  }
</script>

Help would be highly appreciated.


You can use is() with the :checked selector and do something like:

function addClass()
{
    if (!$j("#test_id").is(":checked")) {
        $j(".test").addClass("test2");
    }
}


function addClass() {
  if($("#test_id:not(:checked)")[0]){
      $('.test').addClass('red');  
  }
}

iif #test_id is :not :checked then add the required class.

Demo: http://jsbin.com/unetal


<script type="text/javascript">
function addClass() {
if($(test_id).attr("checked") != "checked"){
       $j('.test').addClass('test2');  
     }
}
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜