javascript - Get onclick string with jQuery -


i had extract 2nd parameter (array) onclick attribute on image, jquery returned function onclick , not string value expected. had use native method.
quick search says may work browsers ff, not ie. use chrome.

<img src="path/pic.png" onclick="funcname(123456,[12,34,56,78,890]);" /> 

i thought work, it not:

var div = $('div_id'); var onclick_string = $(div).find('img').eq(0).attr('onclick'); var onclick_part = $(onclick_string).match(/funcname\([0-9]+,(\[.*\])/)[1]; // reason \d doesnt work (digit) 

this works

var div = $('div_id'); var onclick_string = $(div).find('img')[0].getattributenode('onclick').value; var onclick_part = $(onclick_string).match(/funcname\([0-9]+,(\[.*\])/)[1]; // reason \d doesnt work (digit) 

is there way of getting 2nd parameter ?

why not store in data property?

<img src="path/pic.png" onclick="funcname(123456);" data-mydata='12,34,56,78,890' />  var div_data = $('div_id').data('mydata').split(','); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -