iam noob @ jquery, and i should load a div generated by php to a place, before a specified element. How can i do that? for example:
<div id="something_big">
<div id="first"></div>
<div id="third"></div>
</div>
Following comes from outside, between first and third div:
<div id="second"></div>
edit: i should merge the "load" and "insertafter" commands somehow
ty
Check out this code : http://jsfiddle.net/b8mzs/1/
You just need add a div, after specified element
jQuery( function() {
jQuery.noConflict();
jQuery("#first").after('<div id="second">2</div>');
});
With this, I'm specifing that after the div with id "first", jQuery should add string (which is another div).
noConflict() function is just my habit of writing in jQuery, you can use $ sign as well instead of it (remove jQuery.noConflict(); then)
To move a container behind another container, I would use the insertAfter() function. The first element is the element, that shall be moved. The second element is the element that shall be above.
$(function(){
$("#second").insertAfter("#first");
});
You want to load something. E.g. if you load a container that is located in another file:
$(function(){
var loadedDiv = $("#randomDiv").load('ajax/test.html #container');
$(loadedDiv).insertAfter("#intro");
});
To see more examples about the load function, visit the jQuery documentation for this function.
Try this one:
$(document).ready(function() {
$('#second').insertAfter('#first');
});
For the record, something clean
$.get("your.php", function(data) {
$(data.trim()).insertBefore('#third');
});