Skip to content Skip to sidebar Skip to footer

How To Change Css Of Element Using Jquery

I have defined a CSS property as #myEltId span{ border:1px solid black; } On clicking a button, I want to remove its border. $('#button1').click(function() { // How to fetch a

Solution 1:

Just use:

$('#button1').click(
    function(){
        $('#myEltId span').css('border','0 none transparent');
    });

Or, if you prefer the long-form:

$('#button1').click(
    function(){
        $('#myEltId span').css({
            'border-width' : '0',
            'border-style' : 'none',
            'border-color' : 'transparent'
        });
    });

And, I'd strongly suggest reading the API for css() (see the references, below).

References:


Solution 2:

If you will use this several times, you can also define css class without border:

.no-border {border:none !important;}

and then apply it using jQuery;

$('#button1').click(function(){
        $('#myEltId span').addClass('no-border');
});

Post a Comment for "How To Change Css Of Element Using Jquery"