0

I want prepend one div using jQuery, But the div has to be generated dynamically, so I can not add it in html.tpl file.

I have tried below code

drupal_add_js('jQuery(document).ready(function () { jQuery("body").prepend("'+download_list()+'"); });', 'inline');


function download_list(){
    $output = "I am testing my div prepend";

    return $output;
}

But it is not working , whats the correct way to do this, please help

I am using Drupal 7

Thanks

1 Answer 1

0

It looks like you were using JS string concatenation syntax in PHP. Try

drupal_add_js('jQuery(document).ready(function () { jQuery("body").prepend("' . download_list() . '"); });', 'inline');


function download_list(){
    $output = "I am testing my div prepend";

    return $output;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.