Wednesday, July 10, 2013

Get Element Attribute Value using jQuery

Create textarea element to enter html content dynamic

// button click
$('#click_elemtn').click(function(){
    var str= $('#html_content').text();
    html = $.parseHTML( str ); // parse text to html
    $.each( html, function( i, el ) {
        var attr = $(el).attr('src'); // attribute name that you want fro the textarea content
        if (typeof attr !== 'undefined' && attr !== false) {
            alert(attr); // attribute value
        }
    });
});

you can get attribute value in alert dialog.

refer below URL for live example

http://jsfiddle.net/RNmJ2/

No comments:

Post a Comment