开发者

Problem with jQuery

if ( !this.labelContainer.append(l开发者_运维技巧abel).length )
 this.settings.errorPlacement
  ? this.settings.errorPlacement(label, $(element) )
  : label.insertAfter(element);

(this code is from validate plugin, it repeats for each input)

label is <label>text</label>

element is <input />

This works good, it adds label directly after the element.

Looks like this:

<dd>
    <div>
        <input />
        <label>text</label>
    </div>
</dd>

How to place label after the <div> (element's parent), not after the element?

Full code of the script:

http://www.jsfiddle.net/YSSCE/1/ (search for label.insertAfter(element))


Use insertAfter. Example on jsFiddle.

$("<label />").text("Label").insertAfter(
    $("input").parent()
);

Updating your code (v2):

this.settings.errorPlacement
      /* not sure what this method do, maybe you need to add .parent() as well*/
    ? this.settings.errorPlacement(label, $(element) )
    : label.insertAfter($(element).parent()); /* insert after the parent */


element.parent gets the parent to the element.

label.insertAfter(element.parent);

or possibly

label.insertAfter($(element).parent);


Change label.insertAfter(element) to label.insertAfter(element.parent())

But this could cause problems if your HTML markup changes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜