0

I have a common class name which repeats itself in different pages. As you can see the class name follows this convention:

article-number-slide-number

These links open a certain slide information. This number is different for each slide, therefore I would like to know if its possible to target

$('.hotspot').click(function() {
        $('...SLIDE-2').animate({right: "0"}, 500);
        return false;
    });

Is it possible to target the end of the class name of an element?

<div class="hotspots-image">

    <img class="image"
         src="IMG-SRC"
         alt=""
        />

    <h1 class="home-banner">
        <em>lala collection</em><br>
        white &amp; fluffy
    </h1>

    <a class="hotspot article-1-slide-2" href="#">
        <span class="hotspot-icon pp-icon icon-hotspot">&nbsp;</span>
        <span class="hotspot-label pp-icon icon-anime-left-arrow">article 1</span>
    </a>
    <a class="hotspot article-2-slide-2" href="#">
        <span class="hotspot-icon pp-icon icon-hotspot">&nbsp;</span>
        <span class="hotspot-label pp-icon icon-anime-left-arrow">article 2</span>
    </a>
    <a class="hotspot article-3-slide-2" href="#">
        <span class="hotspot-icon pp-icon icon-hotspot">&nbsp;</span>
        <span class="hotspot-label pp-icon icon-anime-left-arrow">article 3</span>
    </a>
    <a class="hotspot article-4-slide-2" href="#">
        <span class="hotspot-icon pp-icon icon-hotspot">&nbsp;</span>
        <span class="hotspot-label pp-icon icon-anime-left-arrow">article 4</span>
    </a>
    <a class="hotspot article-5-slide-2" href="#">
        <span class="hotspot-icon pp-icon icon-hotspot">&nbsp;</span>
        <span class="hotspot-label pp-icon icon-anime-left-arrow">article 5</span>
    </a>
    <a class="hotspot article-6-slide-2" href="#">
        <span class="hotspot-icon pp-icon icon-hotspot">&nbsp;</span>
        <span class="hotspot-label pp-icon icon-anime-left-arrow">article 6</span>
    </a>
</div>
1
  • @cVplZ hi, the issue that the answers provided do not answer my question. Your answer is a work around and it works but I'm asking exclusively to select a class by selecting only parts of the class name. Commented Nov 10, 2014 at 11:43

4 Answers 4

1

this will work for you, I dont know is it correct method

   $('.hotspot').click(function() {
        $("a[name$='slide-2']").animate({right: "0"}, 500);
        return false;
    });
Sign up to request clarification or add additional context in comments.

Comments

0
$('.hotspot').click(function() {
        $(this).animate({right: "0"}, 500);
        return false;
});

just use $(this)

Comments

0

You can use:

$(this).animate({right: "0"}, 500);

instead of

 $('...SLIDE-2').animate({right: "0"}, 500);

Comments

0

Since the element you want to animate is also the element you want to click, you just need to use $(this) here:

$(this).animate({right: 0}, 500);

Btw, you don't need " around 0. Save 2 bytes :P

Comments

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.