Hello everyone, faced with such a necessity: a template HTML block is being loaded.

var addItemBlock = $('<span>').load("src/featureAddedStructure.html .featureAdded"); 

The block has the following structure:

 <div class="featureAdded fade in"> <button class="close" data-dismiss="modal" style="padding-right:3px">x</button> <div style="background: " class="featureAddedImg"></div> <div class="featureAddedName"> <p>...</p> </div> </div> 

It is necessary for me before I insert this block on the page to add the values ​​stored in the param1 and param2 variables. I can not understand how this can be done before adding this block to the page.

  • one
    Think, maybe you need templates? - Specter

1 answer 1

To place the downloaded content not immediately in the target span , but as an intermediary hidden container. To the load method add the third function callback function - it will be called immediately after the loaded text is inserted into the hidden container. In this function, it will be necessary to pull the contents of the container into a variable, and search / replace the values ​​of param instead of some placeholder templates. Make the search-replacement 'PARAMxVALUE` to your value:

 <input type="hidden" name="param1" value="PARAM1VALUE" /> <input type="hidden" name="param2" value="PARAM2VALUE" /> 

In your code, I don’t see exactly where the values ​​of param1 and param2 are supposed to be inserted. The second option is to insert values ​​by jQuery's manipulation.

  • Thanks for the hint ... everything was decided Callback function. I forget about them. - mult_ru