jquery - manipulate content inserted by ajax, without using the callback -


I am using Ajax to insert a series of information blocks through a loop. Each of the blocks has a title, and they have long details which are hidden by default. They act like an Eordian, show only one description at a time in all the blocks.

The problem is opening details on the first block, I would really like to do with javascript which was looped in them. Is it possible to manipulate the elements made of an AJAX call without using the callback?

  & lt ;! - Example code - & gt; & Lt; Style & gt; . Placeholder, .long_description {display: none;} & lt; / Style & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Script & gt; / * Yes, this script is in the body, do not know whether it is in the case of * / $ (document) .ready (function () {$ (". Placeholder"). Each (function () {// divs Use blocks block block = $ (this) .html (); // if div is an ID for AJAX POST $ .post ("/ service_app / dyn_block", 'form =' + blockname, function), { Var divname = '#div_' + blockname; $ (divname). Later (data); $ (this) .setupAccrdFnctly (); // real code not}};}); / * this line problem is a problem Referencing AJAX insert code Display long descriptions in / / * first dyn_block * / $ (".dyn_block"). First (). (".long_description") Search AddClass ('active') .slideDown ('sharp');}); & Lt; / script & gt; & lt;! - These lines are generated by PHP - & gt; & lt;! - It is possible to display dyn_blocks - & gt; & lt ;! here but I really But not in - & gt; div id = "div_servicetype" class = "placeholder"> succinctly  

The problem is that asynchronous as AJAX (by default)

  $ first () seems ("long_description.") AddClass ('active') slideDown ('sharp') ("dyn_block.") ....  

Any data will be executed before it becomes available, so you can not escape the callback.

Instead of voting, you can define the following functions

  var amount = $ (". Placeholder"). Shape (); Function AZ Done () {Amount -: If (amount == 0) {$ (".dyn_block"). first (). (".long_description") search. AddClass ('Active'). Slide down ('sharp'); }}  

If you want to process then insert a slide for the first time.

Then the script will look like this

  & lt; Script & gt; / * Yes, this script is in the body, do not know whether it is * / var zodiac = $ (". Placeholder"). Shape (); Function AZ Done () {Amount -: If (amount == 0) {$ (".dyn_block"). first (). (".long_description") search. AddClass ('Active'). Slide down ('sharp'); }} $ (Document) .ready (function () {$ (". Placeholder"). Block (block name = $ (this) .html (); // to block block using each (function () {// divs} Content if div is an AJAX POST $ .post ("/ service_app / dyn_block", 'id =' + blockname, the function for the data is {var divname = '#div_' + blockname; $ (divname) $ (this ) .setupAccrdFnctly (); // real code not}};}); / * this line is a question of problem, it is possible to insert code ajax * / / * long before displaying dyn_block * /}); & Lt; / script & gt;  

Edit: Tip about you Do not know about the weather or whether it is about weather, HTML does not have its javascript, check

As Nick suggested that there is a better way of getting the same thing ( Instead of using ajaxDone function)

  $ (document) .ajaxStop (function () {$ (".dyn_block"). First () (". Long_description "). AddClass ('active') Slidedown ('sharp'); $ (this). Unbund ('ajax');});  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -