I want to databind a gridview on a button click event. so that i am going to add a jQuery function for databind. but that function should be called inside a JavaScript function.
like this,
function btnclick() {
//code
//here i want to call the databind function
}
$(function () {
//code
}
this is just my assumption. i don't know how to combine jQuery function and JavaScript function. any suggestion?
-
4jQuery is a javascript library, so what is the problem ?Hassan– Hassan2014年05月05日 03:54:12 +00:00Commented May 5, 2014 at 3:54
-
can we use both combined? because once i have used javascript and jquery in a same page. but both conflicted. if one works then another will not work. so what i want is simply how to call a jquery method from another javscript function. u can add your own example too. i want just the syantax and the logic. thats it....King of kings– King of kings2014年05月05日 03:56:45 +00:00Commented May 5, 2014 at 3:56
3 Answers 3
You can simply call the function as you call in javascript function. its quiet simple.
$(document).ready(function() {
$("#btn").click(function() {
databind();
});
});
function databind(){
//your code
}
1 Comment
.click(...) call? How about using $("#btn").click(databind);?you can bind the jquery event or use jquery inside a javascript function like this:
function btnClick(){
$("yourelement").bind("eventyouchoose",function(e){
//task to do in when the event is called
});
//perform actions using jquery in the similar way
}
Hope this helps
2 Comments
jQuery is simply a library written in JavaScript, so you can freely call JS/jQuery methods in any scope where they are loaded.
I'm not sure what you meant with your code sample, but a common way to perform an action on click would be with the jQuery click() method like so:
function databind() {
// some kinda magic
}
// pass your previously defined databind function as the callback
$('some-selector').click(databind);
You need to specify a selector to target the clickable button.