jquery highlight image by click -
i have 2 questions:
- 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?
- 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")
- to hightlight chosen image (assuming image id database testing hardcoded in fiddle) use:
$(document).ready(function(){ var id = "img1"; $("#thumbs #"+id).addclass('border-highlight'); });
note: added id's img
tag test.
Comments
Post a Comment