0

in my code i have around 11 image tags , all of them have an id of "#bigimage" i want to change the style of an image on each click on a specific button for the specific image meaning on the first click changing the #bigimage [0] second click changing the #bigimage [1] etc...

this is what i did:

<script>
//click event
$('.jssora05r').click(function() {
var abc=$('#bigimag').length;
var ind=0
$("#bigimag").index(ind).css("display", "block !important");
ind++;
});
</script>

it's not working, could someone help me?

3
  • 1
    You cannot have multiple elements with the same id. Ids are unique to a page view. You should change it to a class and use it that way. Commented May 5, 2015 at 15:49
  • thanks for the fast answer, by saying "and use it that way" you mean like in my example above? Commented May 5, 2015 at 15:51
  • 1
    Insead of <img id="bigimag"> it would be <img class="bigimag"> and then the selector would change to $('.bigimag') Commented May 5, 2015 at 15:53

1 Answer 1

1

just declare ind out side of the click event

also you need to change that id selector to some class selector and add same class to all images

<script>
var int = 0;

//click event
$('.jssora05r').click(function() {
   // change id to some class
    var abc=$('.someclass').length;

    $(".someclass").index(ind).css("display", "block !important");
    ind++;
});

Sign up to request clarification or add additional context in comments.

1 Comment

$('#bigimag').length would always be 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.