я не знаю такого селектора, но легко написать
jQuery.expr [':']. Empty = function (obj) {
return jQuery (obj) .text (). replace (/ ^ \ s + | \ s + $ /, "") .length == 0;
}
jQuery.expr[':'].hasNoText = function(obj) {
return jQuery.trim(jQuery(obj).text()).length == 0;
}
и затем, например
$("#layer6 span:hasNoText").text("NEW TEXT")
только для пользы googlers, вот расширенная версия. $ ("узел: соответствует (/ regexp /)") выбирает узлы, текстовое содержимое которых соответствует заданному регулярному выражению.
<script>
/// :matches(regexp)
/// regexp is like js regexp except that you should double all slashes
jQuery.expr[':'].matches = function(obj, index, args) {
var m = (args[3] + "").match(/^\/(.+?)\/(\w*)$/);
var re = new RegExp(m[1], m[2]);
return jQuery(obj).text().search(re) >= 0;
}
</script>
демо:
<script>
$(function() {
$("div").click(function() {
$("div:matches(/foobar/)").text("foobar was here")
$("div:matches(/foo\\s+bar/i)").text("some text")
$("div:matches(/^\\s+$/)").text("only spaces")
});
});
</script>
html before
<div>foobar</div>
<div>Foo Bar</div>
<div> </div>
html after
<div>foobar was here</div>
<div>some text</div>
<div>only spaces</div>