0

I want to change the "float" property to "left" using jQuery. This is the css code:

.dropdown-submenu>a:after {
    display: block;
    content: " ";
    float: right;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    border-width: 5px 0 5px 5px;
    border-left-color: #cccccc;
    margin-top: 5px;
    margin-right: -10px;
}

How can i do this?

annsaid
  • 23
  • 5
  • 1
    You can't change pseudo elements like `:after` with jQuery – adeneo Jan 19 '16 at 23:04
  • Pseudo elements aren't actually nodes, they don't exist in the DOM. Therefore you cannot use the DOM API to access them. As jQuery is just an unnecessary abstraction of the DOM API, you cannot use jQuery to access them either. – Random Logic Jan 19 '16 at 23:07
  • http://stackoverflow.com/questions/5041494/selecting-and-manipulating-css-pseudo-elements-such-as-before-and-after-usin – Seano666 Jan 19 '16 at 23:07
  • @Seano666 That's a cool trick with the content CSS property, but doesn't help the OP in this case as you cannot currently set the float property relative of a data attribute. – Random Logic Jan 19 '16 at 23:09

1 Answers1

0

Add another class in your CSS

.dropdown-submenu>a:after {
    display: block;
    content: " ";
    float: right;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
    border-width: 5px 0 5px 5px;
    border-left-color: #cccccc;
    margin-top: 5px;
    margin-right: -10px;
}

.dropdown-submenu>a.changed:after {
    float: left;
}

Then change the class of the anchor to apply those styles to the pseudo element

$('.dropdown-submenu > a').addClass('changed');

FIDDLE

If you can't add styles for some reason, you can always add them with Javascript

$('head').append(
    $('<style />', { 
        type : 'text/css',
        text : '.dropdown-submenu > a:after {float: left;}' 
    })
);

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388
  • This is what i was really searched for. Thank you so much. .dropdown-submenu>a.changed:after { float: left; } $('.dropdown-submenu > a').addClass('changed'); – annsaid Jan 20 '16 at 11:26