invoking a block and attaching it to a specific html element I have been having this problem for quite some time now and I don't know how to proceed.

I am trying to get a block by invoking it, the simple way:

 $block2 = module_invoke("module", "block_view", "nameofblock");
  print $block2["content"];


and insert it after a specific div with a unique id.

I tried using JavaScript and jquery:

(function($,Drupal,window,document,undefined){$(document).ready(function(){ 
$('#page-title,page').append('#invokedblockid'); 
 });})(jQuery,Drupal,this,this.document);


//and

document.getElementById("page").appendChild(document.getElementById("invokedblockid"));


//and all these

(function($) {

$(window).ready(function() {
$("page-footer-wide").detach().append("page-title");
$("#faresisgod").insertBefore("#page");
$("#faresisgod").appendTo("#page");
});})(jQuery)


but still the block is rendered where i originally added it, and if i put php inside of javascript, the new block will return a  and close my script prematurely...

so is there a way to show this block in the specific div id by using javascript/jquery or is there a way to use php aray to check for the required id then invoking the block.

this is giving me a headache for quite sometime and i am out of options.

thanks in advance
You can achieve this by creating a custom module which prints block content as shown below:

&lt;?php
function mymodule_menu(){
    $items = array();

    $items['ajax/replace/block'] = array(
        'title' =&gt; t('Ajax Block'),
        'page callback' =&gt; 'ajax_callback',
        'access callback' =&gt; true,
        'type' =&gt; MENU_NORMAL_ITEM
    );

    return $items;
}

function ajax_callback(){
    $block2 = module_invoke("block", "block_view", 1);
    print $block2["content"];
}


Then add following jQuery line in your page to replace the target element with block content:

jQuery("#target-selector").load("/ajax/replace/block");