1

I have a string that contains html elements such as the following

var elements = "<div class='instance' id=''><h1></h1></div>";

how can work with it in order to be able to make like this

$('instance').prop('id',5);
$('instance h1').html('hello all');
palAlaa
  • 8,279
  • 28
  • 97
  • 158

1 Answers1

1

You can load it directly into a new jQuery object:

$(elements).find("h1").html("Hello All").appendTo("body");

Also, 5 is not a valid id - please don't use numbers at the beginning of an id value.

Sampson
  • 251,934
  • 70
  • 517
  • 549