for example

var variable = "plus"; $('#id').click(function(){ $(this).html('текст'+variable+'текст'); }) 
  • What do you mean by the words "was visible inside html() "? - LeD4eG
  • That the code worked and all. It should replace the contents of the block with "textplustext". And as I wrote, it does not work - Idaho37

3 answers 3

There was such a trouble. Solved the problem by concatenating a variable before inserting it into $ .html ()

  • I know that the way the curve, but it worked - kemerov4anin

What's the problem? Despite the fact that onclick is an event, and it will work after the external code, the variable variable will be available inside the handler.

This useful JavaScript feature is called closure .

    I'm not sure that I was able to solve your evil and brilliant idea, but it seems to me that in your case it would be possible to get out using the live function that successfully binds the handler to all newly created elements.