jquery highlight image by click -


i have 2 questions:

  1. i'm using code: http://jsfiddle.net/9rfkb/

as can see when click on image getting bold border, , field "size" name of image. how can image id value?

  1. when load page want chosen image bold border. need add?

thanks!

<p id="thumbs">     <input type="hidden" name="size">       <img src='images/size1.png' id='1' />     <img src='images/size2.png' id='2' />     <img src='images/size3.png' id='3' />     <img src='images/size4.png' id='4' />                 </p>    <script> $('#thumbs').delegate('img', 'click', function() {     var $this = $(this);      $('#thumbs img').removeclass('border-highlight');       $this.addclass('border-highlight');       $('[name="size"]').val( $this.attr('src').substring($this.attr('src').lastindexof('/')+1) ); //    alert( $('[name="size"]').val() ); }); </script> 

1.use below 1 on click of image image id:

 $(this).attr("id") 
  1. to hightlight chosen image (assuming image id database testing hardcoded in fiddle) use:
$(document).ready(function(){ var id = "img1"; $("#thumbs #"+id).addclass('border-highlight'); }); 

demo fiddle

note: added id's img tag test.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -