Ali Najm Ali Najm - 25 days ago 7
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.

Example:

<div id="email">useremail@gmail.com</div>


I want to print email address here

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


Thank you very much!

Answer

I would suggest to not use document.write.

If I understand you, using jquery:

(function($)
{
    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
})(jQuery);