how to remove :before:fist-child with jquery?
3 posters
Page 1 of 1
how to remove :before:fist-child with jquery?
hello,
i'm add pseudo element (::before) in .postmain and i want to remove pseudo element only in first .postmain, i try this jquery but not work.
anybody help me, please
i'm add pseudo element (::before) in .postmain and i want to remove pseudo element only in first .postmain, i try this jquery but not work.
- Code:
$(function() {
$(".postmain::before:first").css("display", "none");
});
anybody help me, please
Last edited by kumotta on August 15th 2016, 5:28 pm; edited 1 time in total
Re: how to remove :before:fist-child with jquery?
Hi @kumotta,
Unfortunately you cannot modify pseudo-elements like this, because they do not exist in the DOM -- only the stylesheet. So your best choice would be to hide it with CSS OR add a classname to the first instance of this element.
if it isn't the first child you can also try using nth-child :
It depends on the use case and where in the DOM your element is. I'd recommend looking over the selectors here :
http://www.w3schools.com/cssref/css_selectors.asp
Then you can use the new class to hide your pseudo element :
Unfortunately you cannot modify pseudo-elements like this, because they do not exist in the DOM -- only the stylesheet. So your best choice would be to hide it with CSS OR add a classname to the first instance of this element.
CSS
If this element is the first child of its parent you can use this method :- Code:
.postmain:first-child:before {
display:none;
}
if it isn't the first child you can also try using nth-child :
- Code:
.postmain:nth-child(1):before {
display:none;
}
It depends on the use case and where in the DOM your element is. I'd recommend looking over the selectors here :
http://www.w3schools.com/cssref/css_selectors.asp
JavaScript
As I said before you can also add a className to the element and hide it that way. For example :- Code:
$(function() {
$(".postmain")[0].className += 'hidePseudo';
});
Then you can use the new class to hide your pseudo element :
- Code:
.postmain.hidePseudo:before {
display:none;
}
Re: how to remove :before:fist-child with jquery?
Problem solved & topic archived.
|
Lost Founder's Password |Forum's Utilities |Report a Forum |General Rules |FAQ |Tricks & Tips
You need one post to send a PM.
You need one post to send a PM.
When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
Similar topics
» JQuery Help
» JQuery Slide up and down
» Jquery Cookie Problem
» JQuery Codes.
» drop down menu with jQuery and CSS
» JQuery Slide up and down
» Jquery Cookie Problem
» JQuery Codes.
» drop down menu with jQuery and CSS
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum