How to get onclick event parameters with jquery

I have a set of radio buttons that have a unique name and identifier, but the value for each radio station is the same and the onclick event, what I want to get are the parameters that are inside the click event of the marked radio button on the finished document.

<input id="lvCP_CP1_0_rbC_0" type="radio" name="lv$ctrl0$UC1$CP" value="rbC" checked="checked" onclick="SetCPPrice('lvCP_CP1_0_rbCPSelected_0','Total:5','CPID:wrAtPJQGUiuKfptENuMumY/M7utu6gZ3VMRy3KI1P9rNCokUUO','CPPriceUS:75.9878666666667','CPriceEU:107.53');">
+3
source share
1 answer
var onClickAttribute = $('#lvCP_CP1_0_rbC_0').attr('onclick');

I have no idea why you need it, but the way you can do it.


If you want to split the string into parameters:

var str = $('#lvCP_CP1_0_rbC_0').attr('onclick');   
var params = str.split("SetCPPrice(")[1].split(',');
params[params.length - 1] = params[params.length - 1].replace(');');
console.log(params);​

Live demo

Disclaimer : You must not use this.

+5
source

All Articles