-1

is it possible to call an onclick event in each cases of this code

  buildPager: function(slideIndex){
switch(slideIndex){
  case 0:
    return '<img src="images/mask.png">';
  case 1:
    return '<img src="images/mask.png">';
  case 2:
    return '<img src="images/mask.png">';
  case 3:
    return '<img src="images/mask.png">';
  case 4:
    return '<img src="images/mask.png">';
}
}

because each cases are clickable so there must be a code for it, and that code is inside another code which is this:

<script>
$(document).ready(function(){
$('.slider1').bxSlider({
slideWidth: 5000,
minSlides: 1,
maxSlides: 1,
slideMargin: 10,
infiniteLoop: true,
hideControlOnEnd: false,
mode: 'horizontal',
useCSS: false,
easing: 'easeOutElastic',
speed: 2000,
buildPager: function(slideIndex){
switch(slideIndex){
  case 0:
    return '<img src="images/mask.png">';
  case 1:
    return '<img src="images/mask.png">';
  case 2:
    return '<img src="images/mask.png">';
  case 3:
    return '<img src="images/mask.png">';
  case 4:
    return '<img src="images/mask.png">';
     }
   }
 });
 });
 </script>

it's a bxslider code.

1 Answers1

2

You have several options:

  • bind click event using id's, e.g. $("#image_1").click(function(){});

  • bind click event using a class selector, e.g. $(".slider-image").click(function(){});

  • bind click event using the tag itself, e.g. $("img").click(function(){});, but this will bind a click event to all images on the page, unless you surround them with a class-specfic container, in that case $(".containerName img").click(function(){});

Mark Erasmus
  • 2,305
  • 6
  • 25
  • 37
  • Another option is delegation, which is probably a safer bet here, since we don't know what's going on: `$('.slider1').on('click', 'img', function(){});` (assuming the images are appended to .slider1). – bfavaretto Aug 30 '13 at 14:41
  • i mean is this code posible? so far so on ... its what im trying to acheive because im gonna use it on a navigation (jquery) but the code with those cases is on a different jquery which is the bxslider – Ciprian Patrimonio Diola Jr II Aug 30 '13 at 14:46
  • the cases are links which is slides to a content which maybe we can set it up on a tag link with an onclick ... – Ciprian Patrimonio Diola Jr II Aug 30 '13 at 15:00
  • @CiprianPatrimonioDiolaJrII, binding events using onClick() is considered outdated and you should try to use more modern techniques for event registration. See this [post](http://stackoverflow.com/questions/12627443/jquery-click-vs-onclick) for a good explanation on the topic. – Mark Erasmus Aug 30 '13 at 15:24