Finding the name of method in jquery -


i trying find method names in html code. find method name in 'onclick' attribute , make operations.

this current code:

<div class="button" style="width: 60px; float: right;" onclick="closemodaldialog('dialogattachmentmodal');">blabla</div> 

i want write jquery this:

$('closemodaldialog').attr('id','btnclosemodal'); 

and want show this:

<div class="button" id="btnclosemodal" style="width: 60px; float: right;" onclick="closemodaldialog('dialogattachmentmodal');">blabla</div> 

i know, selector must id or class. want add attribute this.(because have more 'button' class , want add one) possible? how can succeed? thx in advance , sorry language.

you can use 'attribute begins selector' this:

$('[onclick^="closemodaldialog"]').prop('id', 'btnclosemodal'); 

note it's better practice use prop() set domelement properties, , if there multiple elements have onclick attribute end duplicate id value - render page invalid.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -