Ali Najm Ali Najm - 1 year ago 92
Javascript Question

Get div content inside (javascript code) using jquery or any way

I trying to get the #email div content insdie my javascript code.


<div id="email">[email protected]</div>

I want to print email address here

document.write('<img src="' + get_gravatar('Email Here', 150) + '" />');

Thank you very much!

Answer Source

I would suggest to not use document.write.

If I understand you, using jquery:

    var $img = $('<img></img>'); //create img tag using jquery
    var email = $('#email').text().trim() //could also be .html() to get inner html
    $img.attr('src', get_gravatar(email, 150) ) //add email to src attribute of img tag 
    $('body').append($img); //change 'body' with whatever you want to add it to; this will append the img tag into the document
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download