Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do not addClass if option is checked

Tags:

jquery

css

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="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.

like image 457
Ruud Avatar asked Feb 23 '26 21:02

Ruud


1 Answers

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

function addClass()
{
    if (!$j("#test_id").is(":checked")) {
        $j(".test").addClass("test2");
    }
}
like image 66
Frédéric Hamidi Avatar answered Feb 25 '26 12:02

Frédéric Hamidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!