문제

Possible Duplicate:
Why does jQuery .after() not chain the new element?

This reference code:

$("#id").after(string);

Does a pretty good job inserting the element of the string where its need to.

How can I get a reference to newly inserted HTML element (string)?

도움이 되었습니까?

해결책

var string = '<div id="some_HTML"><span>hello kitty</span></div>';

$jq_elem = $(string);  //if it's not a jQuery object, make it one

$("#id").after($jq_elem); //insert into DOM

$jq_elem.css('color', 'red'); //still available
​

FIDDLE

다른 팁

Try using insertAfter:

var $str = $(string).insertAfter('#id');

This will work if string is HTML.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top