Jquery after it does not work for loose objects

I need to create two objects separately, and then add one by one and return the combined object from the function. My requirement is that I have to add this object outside the function, and the function should return 2 created objects as one. See code below. it returns only div. no table?

function html() {
var _tab = $("<table>").attr("id", "table_1")
var _div = $("<div>").attr("id", "div_1").text("test");
return  _div.after(_tab);
}

$("body").append(html()); // only returns div .. no table
+4
source share
4 answers

I had to use . add () for this ... Solved !!!

_div.add(_tab);
+3
source

, jquery , jquery > 1.4 (http://api.jquery.com/after/#after-content-content ) jquery 1.9.1, 1.6.4- > 1.8.3

http://jsfiddle.net/XSXYW/

apparantly i need code to post fiddle links

?

+1
function html() {
    var _tab = $("<table>").attr("id", "table_1")
    _tab.html('<tr><td>Hi all</td></tr>');
    var _div = $("<div>").attr("id", "div_1").text("test");
    return  _div.after(_tab);
    }

    $("body").append(html());

. , .

0
return _div + _tab

,

after , 2, , _div _div dom, _div div + tab? _div?

0

All Articles