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
});
The css() method in JQuery is used to change the style property of the selected element. The css() in JQuery can be used in different ways. Return value: It will return the value of the property for the selected element.
You can change CSS using the jQuery css() method which is used for the purpose of getting or setting style properties of an element. Using this method you can apply multiple styles to an HTML all at once by manipulating CSS style properties.
Apply multiple CSS properties using a single JQuery method CSS( {key1:val1, key2:val2....). You can apply as many properties as you like in a single call. Here you can pass key as property and val as its value as described above.
Get a CSS Property Value You can get the computed value of an element's CSS property by simply passing the property name as a parameter to the css() method. Here's the basic syntax: $(selector). css("propertyName");
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:
css()
.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');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With