The script was written for this structure:

<div class="catalog"> <img src="img/name12.jpg"/> <a href="cat/tovar1.html">товар 1</a> </div> 

And I have this:

 <div class="title"> <h2 itemprop="name"><a href="cat/tovar1.html" itemprop="url">товар 1</a></h2> </div> <div class="miniature"> <img itemprop="image" src="img/name12.jpg"/> </div> 

Here is a script that needs a little tweak:

 jQuery(document).ready(function(){ $('.catalog img').live('click', function() { document.location.replace($(this).parent().find('a').attr('href')); }); }); 

Thank.

  • one
    Try this: document.location.replace ($ (this) .parent (). Prev ('. Title'). Find ('a'). Attr ('href')); - RedMonkey

1 answer 1

Through jQ it will be like this:

 jQuery(document).ready(function(){ $('.miniature img').live('click', function() { document.location.replace( $(this).parent().prev('.title').find('a').attr('href') ); }); }); 

Should work. In general, it is wiser to make such a structure:

 <div class="title"> <h2 itemprop="name"> <a href="cat/tovar1.html" itemprop="url">товар 1</a> </h2> </div> <div class="miniature"> <a href="cat/tovar1.html"> <img itemprop="image" src="img/name12.jpg"/> </a> </div> 

Without any js.

  • I need to remove extra links for seo. - rodion
  • @rodion so you nofollow potavte, or whatever ... - igolka97
  • They say it is not entirely reliable, but surely so. - rodion