I had to extract the second parameter (array) from the onclick attribute in the image, but jQuery just returned the onclick function and not its string value as expected. So I had to use my own method.
A quick search says that it can work with some browsers, such as FF, but not with IE. I am using Chrome.
<img src="path/pic.png" onclick="funcName(123456,[12,34,56,78,890]);" />
I thought this would work, but this is 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];
It 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];
Is there any other way to get the second parameter?
source
share