将 propertey 之后的 CSS 转换为 jQuery

convert css after propertey to jquery

本文关键字:转换 jQuery CSS propertey 之后      更新时间:2023-09-26

我想使用 jQuery 将 "float" 属性更改为 "left"。这是 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;
}

我该怎么做?

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

然后更改定位点的类以将这些样式应用于伪元素

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

小提琴

如果由于某种原因无法添加样式,则始终可以使用Javascript添加样式

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

小提琴