Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  66] [ 5]  / answers: 1 / hits: 19418  / 8 Years ago, thu, june 9, 2016, 12:00:00

I have something like this:



<button id=button1 onClick=someFunc('arg1','arg2')> </button> 


Is it possible in JavaScript to change parameters of the function someFunc to look like below:



<button id=button1 onClick=someFunc('somethingDiff1','somethingDiff2')> </button> 

More From » jquery

 Answers
11

Try this



If you want in jquery then try this



$(document).ready(function(){
var clickfun = $(#button1).attr(onClick);
var funname = clickfun.substring(0,clickfun.indexOf(());
$(#button1).attr(onclick,funname+('somethingDiff1',+'somethingDiff2'));
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<button id=button1 onClick=someFunc('arg1','arg2')>Button1</button>





If you want in JavaScript then try this:-



<script>
window.onload=function(){
var clickfun = document.getElementById(button1).getAttribute(onclick);
var funname = clickfun.substring(0,clickfun.indexOf(());
document.getElementById(button1).setAttribute(onclick,funname+('somethingDiff1',+'somethingDiff2'));
};
</script>


Hope This will help you.


[#61832] Tuesday, June 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maryann

Total Points: 600
Total Questions: 104
Total Answers: 97

Location: Sint Maarten
Member since Tue, Mar 29, 2022
2 Years ago
;