Friday, 15 August 2014

javascript - find and replace html( not only text ) in ckeditor? -



javascript - find and replace html( not only text ) in ckeditor? -

i using ckeditor 4 in application.

here have type of tag, let's 'tagx'.

i need add together 'id' attribute tagx tags doesn't have id.

i have trued using:

content = editorinstance.getdata(); var pattregex = /<(tagx)(?![^<>]*\bid=).*?<\/\1>/gi; var arrtagsx = content.match(pattregex); (i = 0; < arrtagsx.length; i++) { content = content.replace("<tagx", <tagx id=\"id_" + + "\""); } editorinstance.setdata(content);

its working fine, content size big want avoid setdata();.

i want find html (not text) , replace html html+id.

why not using $('tagx') , utilize $(this) staff later while displaying ?

so let's give job jquery following

var i=0; $('tagx').each(function(){ i++; $(this).attr('id','id_'+i); });

edit regarding other comment

let's test if :not([id])

var i=0; $('tagx:not([id])').each(function(){ i++; $(this).attr('id','id_'+i); });

javascript jquery asp.net ckeditor

No comments:

Post a Comment