I want to know if it is possible to use universal selector with $(this)
.
When, for example, I want delete all inline CSS from the element and its children I use this code:
$('#element, #element *').attr('style','');
But if i have $(this)
what is the code?
Maybe I have to try:
$(this, this+'*').attr('style','');
Universal Selector in CSS is used to select all the elements on the HTML page. It is denoted by an asterisk (*).
The Universal Selector is the * in CSS. Literally the asterisk character. It is essentially a type selector that matches any type. Type meaning an HTML tag like <div> , <body> , <button> , or literally any of the others.
Universal CSS Selector The three lines of code inside the curly braces ( color , font-size , and line-height ) will apply to all elements on the HTML page. As seen here, the universal selector is declared using an asterisk. You can also use the universal selector in combination with other selectors.
Universal Selector It matches a single element. An asterisk ( i.e. "*" ) is used to denote a CSS universal selector. An asterisk can also be followed by a selector. This is useful when you want to set a style for of all the elements of an HTML page or for all of the elements within an element of an HTML page.
You can either use find()
$(this).find('*').attr('style','');
or the context selector
$('*', this).attr('style','');
to do the same thing as $('#element *')
with this
If the element represented by this
should be part of the collection, you can add it back
$(this).find('*').addBack().attr('style','');
I tend to agree with Rory McCrossan in the comments, using a parent element and external styles would be preferable to changing the style attribute on multiple elements
.element.styled * { /* styles for all children */ }
then just
$('.element').removeClass('styled')
to remove the styles on the children
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