10

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 all those spans and remove their border
});

2 Answers 2

29

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:

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks David.I tried the same but it was not working for me because of some silly mistake..sorry my bad
No worries; glad to have been of (some, small) help anyway. Even if only to verify your original approach.
5

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');
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.