The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

how to remove :before:fist-child with jquery?

View previous topic View next topic Go down

Solved how to remove :before:fist-child with jquery?

Post by kumotta on August 15th 2016, 1:09 pm

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.
Code:

$(function() {
$(".postmain::before:first").css("display", "none");
});

anybody help me, please Crying or Very sad


Last edited by kumotta on August 15th 2016, 5:28 pm; edited 1 time in total

kumotta
Forumember

Female Posts : 204
Reputation : 3
Language : English

http://komiku.forumid.net/

Back to top Go down

Solved Re: how to remove :before:fist-child with jquery?

Post by Ange Tuteur on August 15th 2016, 4:28 pm

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.


CSS

If this element is the first child of its parent you can use this method :
Code:
.postmain:first-child:before {
  display:none;
}
see :first-child : http://www.w3schools.com/cssref/sel_firstchild.asp


if it isn't the first child you can also try using nth-child :
Code:
.postmain:nth-child(1):before {
  display:none;
}
see :nth-child : http://www.w3schools.com/cssref/sel_nth-child.asp

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

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: how to remove :before:fist-child with jquery?

Post by kumotta on August 15th 2016, 5:28 pm

last solution working Very Happy
thanks @Ange Tuteur Smile
problem solved Smile

kumotta
Forumember

Female Posts : 204
Reputation : 3
Language : English

http://komiku.forumid.net/

Back to top Go down

Solved Re: how to remove :before:fist-child with jquery?

Post by SLGray on August 15th 2016, 9:54 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 36705
Reputation : 2445
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum