-1

This should be a tweak for the jQuery based image gallery "Galleria". You can click on a thumbnail div called images and it brings you on the site based on the url in the class of the a tag.

Pseudo Code HTML

<div id="galleria">
    <div class="images"><a class="www.google.com" href="bens_img/1.jpg"><img src="bens_img/thumb1.jpg"></a>
    <div class="images"><a class="www.yahoo.com" href="bens_img/2.jpg"><img src="bens_img/thumb2.jpg"></a>
    <div class="images"><a class="www.tokyo.co.jp" href="bens_img/3.jpg"><img src="bens_img/thumb3.jpg"></a>
</div>

Pseudo JQuery (JavaScript)

Get Value from class of <a>
Onclick ".images".this
href to Value from class of <a>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tomkay
  • 5,120
  • 21
  • 60
  • 92

3 Answers3

0

If i've understood correctly,

$('galleria.images').click(function(){
   window.location.href = $("a", this).attr('class');
});

//although i wonder why you'd put href's within a class attribute. hmmm..

Do take a look at this SO post on valid characters for CSS classes.

Community
  • 1
  • 1
Robin Maben
  • 22,194
  • 16
  • 64
  • 99
0

Unless I'm missing something, is there any reason why the URL is in the class of the anchor? You have the image path in the href (normally reserved for the destination URL), and then you have a nested img tag with the same reference. Wouldn't your code look more like this?

    <div class="images"><a href="www.google.com"><img src="bens_img/thumb1.jpg"></a></div>
Ryan Eastabrook
  • 4,085
  • 5
  • 30
  • 35
  • Galleria usully interprete it like this:
    - And I need a tweak, when you click on the div (which contains the thumnail.jpg) then you where href'ed to another webpage.
    – Tomkay Nov 24 '10 at 07:59
  • did you add the class="www.google.com" then? Or was it the plugin? – Ryan Eastabrook Nov 24 '10 at 08:08
0

Putting this in the $(document).ready(function() { ... }) should fix it.

$('#galleria div.images a').each(function(){
   $(this).attr("href", "http://" + $(this).attr('class'));
});

You're missing closing </div> tags on each of the <div class="images"> too BTW.

Edit: http://jsfiddle.net/Ku6Pc/ is an example to show it working.

Michael Low
  • 24,276
  • 16
  • 82
  • 119