The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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

3 posters

Go down

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

Post by kumotta 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
kumotta
Forumember

Female Posts : 203
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 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
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

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

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

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

Female Posts : 203
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 August 15th 2016, 9:54 pm

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


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

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

Male Posts : 51520
Reputation : 3523
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Back to top

- Similar topics

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