Search code examples
jqueryhtmlrel

Get attributes from the rel attribute with jQuery


Im using a plugin that requires the rel-element to look like this.

<ul id="product-thumbs-list">
      <li><a href="1-big.jpg" rel="useZoom: 'cdonZoom', smallImage: '1.jpg'"></li>
      <li><a href="2-big.jpg" rel="useZoom: 'cdonZoom', smallImage: '2.jpg'"></li>
</ul>

Is it possible to get the smallImage-value via jQuery?
In this case, '1.jpg, or '2.jpg'.

Thanks!


Solution

  • Here is one way:

    $("#product-thumbs-list a").each(function(index) {
       var arrTemp = $(this).attr("rel").split("smallImage: ");
       var value = arrTemp[1];
       alert(value);
    });
    

    Live test case.