JQuery If this image is on a page, add this meta tag?

I am trying to add rich fragments to a dynamic image that displays stars. The only thing my basket writes is the image, so I have to find which image is displayed, and then add the correct meta tag.

So, if the displayed image is 1stars.gif, I have to write:

<meta itemprop="ratingValue" content="1" /> 

and if the displayed image is 5stars.gif, I have to write:

 <meta itemprop="ratingValue" content="5" /> 

The following is the UPDATED full example:

 <span id="rateitnow"> {module_ratingrank,images/icons/stars} <meta itemprop="ratingValue" content="" /> </span> <script type="text/javascript"> jQuery(document).ready(function($) { $('#rateitnow meta').attr('content', $('#rateitnow').find('img:first').attr('src').substr(0,1)); }); </script> 
+4
source share
1 answer
 $('#rate-me meta').attr('content', $('#rate-me').find('img:first').attr('src').substr(0,1)); 
0
source

Source: https://habr.com/ru/post/1404023/


All Articles