0

Am having a trouble with following code. The problem when adding the following style from jquery.

CSS

  .arrow_box {
position: absolute;
width: 24px;
border-radius: 30px 30px 3px 3px;
height: 17px;
float:left;
 }
.arrow_box:after {
border-color: rgba(136, 183, 213, 0);
border-top-color: #88b7d5;
border-width: 14px;
left: 0%;
 }

jQuery

<script type="text/javascript">
$(document).ready(function () {
    $('.arrow_box:after').css({
        "border-color": "red",
            "border-top-color": " #88b7d5",
            "border-width": "12px",
            "left": "0%"
    });
});
</script>

There will not have any jquery error but it is not working

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
Well Wisher
  • 1,785
  • 1
  • 14
  • 20
  • possible duplicate of [Setting CSS pseudo-class rules from JavaScript](http://stackoverflow.com/questions/311052/setting-css-pseudo-class-rules-from-javascript) – Felix Kling Sep 14 '13 at 10:38
  • stackoverflow.com/questions/5041494/manipulating-css-pseudo-elements-using-jquery-e-g-before-and-after/5335771 and http://stackoverflow.com/questions/8095177/jquery-using-after-selector. It would have benefited had you yourself looked this up. – verisimilitude Sep 14 '13 at 10:41

3 Answers3

2

You can't directly do this with jquery. But here solution with pure javascript http://www.4pmp.com/2009/11/dynamic-css-pseudo-class-styles-with-jquery/

Krasimir
  • 13,032
  • 3
  • 39
  • 54
  • The link is broken. I found this: https://web.archive.org/web/20170616025900/http://www.4pmp.com/2009/11/dynamic-css-pseudo-class-styles-with-jquery/ – Emmanuel Jun 28 '18 at 18:51
1

Pseudo elements are not DOM elements targetable with JavaScript.

Mitya
  • 32,084
  • 8
  • 49
  • 92
1

Pseudo elements are not DOM elements so you can not access them using JavaScript or jQuery.

Tushar Gupta - curioustushar
  • 56,454
  • 22
  • 99
  • 107