AiD*_*AiD 9 javascript css jquery
我想选择伪元素 :after
这是我的css:
show-more:after
{
content : (" > ");
}
Run Code Online (Sandbox Code Playgroud)
JQuery 码
$(function(){
$('.show-more:after').click(function() {
alert("Yes");
});
});
Run Code Online (Sandbox Code Playgroud)
编辑、更新
尝试
(function($) {
jQuery.fn.extend({
getPseudo: function(pseudo, prop) {
var props = window.getComputedStyle(
$(this).get(0), pseudo
).getPropertyValue(prop);
return String(props);
},
setPseudo: function(_pseudo, _prop, newprop) {
var elem = $(this);
var s = $("style");
var p = elem.getPseudo(_pseudo, _prop);
var r = p !== "" ? new RegExp(p) : false;
var selector = $.map(elem, function(val, key) {
return [val.tagName
, val.id
? "#" + val.id : null
, val.className ? "." + val.className : null]
});
var _setProp = "\n" + selector.join("")
.toLowerCase()
.concat(_pseudo)
.concat("{")
.concat(_prop + ":")
.concat(newprop + "};");
return ((!!r ? r.test($(s).text()) : r)
? $(s).text(function(index, prop) {
return prop.replace(r, newprop)
})
: $(s).append(_setProp)
);
}
})
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
例如,初始css:
.show-more:after {
content : ' > ';
}
Run Code Online (Sandbox Code Playgroud)
设置pseudo元素
$(".show-more-after").on("click", function() {
$(this).setPseudo(":after", "content", "'123'")
})
Run Code Online (Sandbox Code Playgroud)
github伪.js
(function($) {
jQuery.fn.extend({
getPseudo: function(pseudo, prop) {
var props = window.getComputedStyle(
$(this).get(0), pseudo
).getPropertyValue(prop);
return String(props);
},
setPseudo: function(_pseudo, _prop, newprop) {
var elem = $(this);
var s = $("style");
var p = elem.getPseudo(_pseudo, _prop);
var r = p !== "" ? new RegExp(p) : false;
var selector = $.map(elem, function(val, key) {
return [val.tagName
, val.id
? "#" + val.id : null
, val.className ? "." + val.className : null]
});
var _setProp = "\n" + selector.join("")
.toLowerCase()
.concat(_pseudo)
.concat("{")
.concat(_prop + ":")
.concat(newprop + "};");
return ((!!r ? r.test($(s).text()) : r)
? $(s).text(function(index, prop) {
return prop.replace(r, newprop)
})
: $(s).append(_setProp)
);
}
})
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
.show-more:after {
content : ' > ';
}
Run Code Online (Sandbox Code Playgroud)
$(".show-more-after").on("click", function() {
$(this).setPseudo(":after", "content", "'123'")
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31519 次 |
| 最近记录: |