0

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?

2
  • 4
    jQuery is a javascript library, so what is the problem ? Commented 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.... Commented May 5, 2014 at 3:56

3 Answers 3

2

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
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Why create an anonymous function inside the .click(...) call? How about using $("#btn").click(databind);?
1

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

it would help but the databind method will be called from some other functions too. its a common function.
well in that case may be you can create a function like initListeners() which holds the jquery code. And call the initListeners() function from the js methods you want.
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.