replacing div tag using next()
var el = $("#id-2");
开发者_高级运维el.insertAfter(el.next($('.mydata'));
i want to swap with the current div(id-2) with the next having class name "mydata" . is this synatx correct ?. its not working?
The next method takes a selector (string) as an argument. By using the $()
method (equivalent to jQuery('selector')
you call it with a set of elements as an argument.
Just pass the selector and it should at least do something.
el.insertAfter(el.next('.mydata');
insertAfter() doesn't exactly swap things around, though. If the target element isn't directly next to the source element, it will just put the source element next to the target.
Consider this:
elements ABCD
Calling A.insertAfter(D)
will result in BCDA
, not DBCA
Try this:
el.after(el.next($('.mydata'));
精彩评论