在空元素之间附加一个单词

时间:2011-09-28 21:47:28

标签: javascript jquery

如果jquery知道如果元素之间是空的,则在相同的元素词之间追加“没有”?

<div>Ok</div>
<div>No</div>
<div></div> // i want append between this div "there is not" that is empty. Like: <div>there is not</div>
<div>Hello</div>

2 个答案:

答案 0 :(得分:3)

尝试 -

$("div:empty").append("there is not");

演示 - http://jsfiddle.net/St8sV/

答案 1 :(得分:0)

More详细形式:

$('div').each(function() {
   if ($(this).html() == '') {
      $(this).html('there is not');
   }
}