Mohan Ram
Mohan Ram

Reputation: 8463

I need to fetch html tags given inside textbox using jquery

I had to fetch html elements and its attributes that is given inside textbox. How can i fetch it using jquery.My code is...

    $("#textbox_id").html().filter('img').each(function() {
        alert($(this).attr("id"));
    });

In my above code i like to get id of all img tags inside textbox...

Upvotes: 0

Views: 165

Answers (2)

Mohan Ram
Mohan Ram

Reputation: 8463

My Final Solution...

$("#textbox_id").html('html content given here');   

$("#textbox_id").find('img').each(function() {
        alert($(this).attr("id"));
    });

Upvotes: 0

David Tang
David Tang

Reputation: 93694

Textboxes don't have html inside them, they only have a value, which you can access via .val(). Then you pass that string to jQuery:

var textboxHTML = $("#textbox_id").val();
$(textboxHTML).filter("img").each(function () {
   alert($(this).attr("id"));
});

Upvotes: 1

Related Questions