Reputation: 2248
I want to declare an array when I am declaring a JQuery function. How do I do that?
If it is possible then how can I pass items to that array in an OnClick event?
For Example:
Function EditGrid(Declare a Array Here?)
{
//Do something…
}
<a href=”javascript:void(0);” onclick=’EditGrid(‘[CategoryName1,CategoryName2,CategoryName2….etc ]’)’>Edit Item</a>
Upvotes: 0
Views: 36
Reputation: 1330
I don't see any jQuery in your example.
If I understand correctly, all you want to do upon clicking on a link/button is to call a function and give it an array, then edit your grid from that.
html:
<button>Edit item</button>
javascript:
function editGrid(array){
array.forEach(function(item){
alert(item);
});
// Edit your grid
}
$(function(){
$("button").click(function(){
editGrid(['categoryName1', 'categoryName2']);
});
});
Let me know if that helps.
Edit:
You could call the editGrid function with different parameters based on which button is clicked.
View my updated Jsfiddle DEMO.
$("#button1").click(function(){
editGrid(['categoryName1', 'categoryName2']);
});
$("#button2").click(function(){
editGrid(['categoryName3', 'categoryName4']);
});
Upvotes: 1