javascript - Get Id from HTML by means of Regular-Expression -
how can test, whether id of object (e.g. image , div or table ...) in html-code. id e.g. follows: id=my_img_id or id="my_img_id" or id = " my_img_id " or id = my_img_id
var shtml = '... text abc < img src="path/myfile.jpg" id="my_img_id" style="..." > ... text'; var sid = 'my_img_id'; var sreg = '<.*? *id*\= *\"*['+sid+' *"*]$.*'; var sregexp = new regexp(sreg, "g"); var result = sregexp.test( shtml ); alert( result );
many in advance.
first convert html string jquery object can use find element jquery object. use length property if more 0 element id exists in html string.
$(shtml).find('#' +sid ).length
Comments
Post a Comment