• Welcome to WebsiteBaker Community Forum. Please log in or sign up.
Welcome, Guest
News
Support WebsiteBaker
Your donations will help to:
PayPal
  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!
You can donate by clicking on the button below.

combined img+href - W3C-Conform???

Started by jacobi22, February 18, 2016, 01:16:36 AM  ( Read 8,538 times )

jacobi22

found a solution for clickable pics without special a-tag arund the img-tag on jsfiddle.

<img src="http://..../img/sprites.png" href="http://....../img/sprites.png" class="myImg"/>

css-class: myImg set width or height for the thumb, the other attribute is set to "auto"

with another code you open the pic with a colorbox-effect
$('img').click(function() {
   $(
this).colorbox({href: $(this).attr('src')});
});


i search in the web for some descriptions, but doesnt found this combination
Is it W3C-conform??

    Ruud

    1. Your colorbox script example does not use the href tag in the image.
    It takes the src attribute and uses that to open the lightbox:   $(this).attr('src')

    2. No, it is not valid to use a href attribute in an image element.
    A better way would be to use a data-* attribute.
    (Custom attributes prefixed with "data-" will be completely ignored by the user agent.)

    Setup like:
    <img src="http://..../img/sprites.png" data-myhref="http://....../img/sprites.png" class="myImg"/>

    Use it like:
    $('img').click(function() {
       $(
    this).colorbox({href: $(this).data('myhref')});
    });

      jacobi22


      pallavidesphande


      \n\n