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.

live demo

$(shtml).find('#' +sid ).length 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -