tags:

views:

82

answers:

1

Hopefully this is a simple question for a jQuery newbee. Is it possible to execute jQuery methods from a javascript method?

I've got some jQuery stuff adding zebra stripes to a table and some other things going on, but that table gets updated via an mvc ajax request and then none of the styles are applied to the table once the ajax call is complete. This is obviously because those styles are applied when the dom is ready only ( it's currently being called with the standard jQuery $(function() {... magic in here }) method).

The ajax request provides a way to execute a javascript method on callback and I'd like to be able to apply those same styles via jQuery from that javascript function.

Thanks in advance!

+1  A: 

jQuery is built in JavaScript; it is a JavaScript framework (or library, depending on how you look at it). There should be no problems executing jQuery from JavaScript, because that's how you execute jQuery in the first place.

You should just be able to pass the same function you provide to jQuery as the callback for your AJAX request. For example (in pseudo-code):

// Define your function ahead of time so that you can reuse it easily.
var myMagicFunction = function() { // magic happens here };

// This occurs when your page loads
$(document).ready(myMagicFunction());

// Assuming that you pass a url and your magic function as the callback
myMagicAJAXCall(url, myMagicFunction);
Daniel Lew