Hello everyone. I need help.
There is such code:

<div><span></span><a href="">Клик</a></div> 

How to make the click on the link change the contents of the span , which is in the parent?

1 answer 1

A rough example:

 <div id="tadam"> <span></span> <a href="javascript://">Клик</a> </div> <script> $('#tadam a').click(function(){ $('#tadam a').prev('span').html('тест'); }); </script> 

For a diva or for a reference, the class or id set is no difference. Create a .click event handler and select the span element that lies before the link using the prev () method.

  • '#tadam a' inside the function should be replaced with this - RedMonkey
  • Yeah, so much better. <script> $ ('# tadam a'). click (function () {$ (this) .prev ('span'). html ('test');}); </ script> - condor