Get Attributes From The Rel Attribute With Jquery
Im using a plugin that requires the rel-element to look like this.
Solution 1:
Here is one way:
$("#product-thumbs-list a").each(function(index) { var arrTemp = $(this).attr("rel").split("smallImage: "); var value = arrTemp[1]; alert(value); });
Solution 2:
you can get the rel attributes that returns the string "useZoom: 'cdonZoom', smallImage: '1.jpg'". Than you can split the string using ":" and get the last array item.
I hope it's helpful
Solution 3:
Superbly ugly, but you can use the dreaded
eval()
, provided that therel
data are "well-formed":$(function() { $('a').mouseover(function() { eval('var rel = {' + $(this).attr('rel') + '};'); $('#out').text(rel.smallImage); }); });
With HTML:
<ulid="product-thumbs-list"><li><ahref="1-big.jpg"rel="useZoom: 'cdonZoom', smallImage: '1.jpg'">link1</a></li><li><ahref="2-big.jpg"rel="useZoom: 'cdonZoom', smallImage: '2.jpg'">link2</a></li></ul><pid="out"></p>
Demo.
Post a Comment for "Get Attributes From The Rel Attribute With Jquery"