1

Is it possible to load jquery code in addition to html via ajax or jquery's post or get methods? I am trying to build conditional gui element activation (based on user's input).

It doesn't make sense to create one file with all jquery code taking all the conditionality into consideration. Instead, my hope is that if jquery via ajax allows me to load jquery code as well, then I can further reduce the jquery based code foot print and load the only code that is relevant conditionally generated elements (rather than the entire deeply nested tree conditionality).

2
  • By jQuery code, do you mean the jQuery library itself? Commented Jun 22, 2010 at 4:14
  • Jquery is already available. I want to be able to load jquery code related to the dynamically loaded (via ajax) html. I think, as Ben suggested getScript() might be the function I am looking for. Thanks Commented Jun 22, 2010 at 16:57

1 Answer 1

2

From personal experience injecting html into the dom that includes script tags causes all sorts of issues.

However jQuery has a handy method called

$.getScript()

that will allow you to dynamically include a javascript file + a success callback to invoke any of the code within the script.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried the above and it worked. I hoped to debug the script in the firebug, but I couldn't. I could see the downloaded script in the console, but it is not available to step thru in the debugger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.