1

I would like to target only the classes "Front" and "Back" of the "Flip-tile" that I am currently hovering over. How do you solve this with javascript, currently it is toggling them all at the same time.

The HTML:

    <div class="flip-tile">
        <div class="front">
            <div class="project-tile primary-color col-md-4 col-xs-12">
                <img class="tile-img" src="../static/img/first.png">
                <div class="tile-text">
                    <h4><span class="light">Front side</span></h4>
                </div>
            </div>
        </div>
        <div class="back" style="display:none;">
            <div class="project-tile secondary-color col-md-4 col-xs-12">
                <div class="tile-text">
                    <h4><span class="light">Back side</span></h4>
                </div>
            </div>
        </div>
    </div>

    <div class="flip-tile">
        <div class="front">
            <div class="project-tile primary-color col-md-4 col-xs-12">
                <img class="tile-img" src="../static/img/first.png">
                <div class="tile-text">
                    <h4><span class="light">Front side</span></h4>
                </div>
            </div>
        </div>
        <div class="back" style="display:none;">
            <div class="project-tile secondary-color col-md-4 col-xs-12">
                <div class="tile-text">
                    <h4><span class="light">Backside</span></h4>
                </div>
            </div>
        </div>
    </div>

The Javascript:

$(".flip-tile").hover(function() {
    $(".front").hide()
    $(".back").show()},
    function() {
    $(".back").hide()
    $(".front").show()
});

4 Answers 4

2

It's so easy using find() on jQuery, but you can make it on easiest way with CSS.

Javascript:

$(".flip-tile").hover(function() {
    $(this).find(".front").hide();
    $(this).find(".back").show();
  },
  function() {
    $(this).find(".back").hide();
    $(this).find(".front").show();
  }
);

CSS solution

.flip-title .front {
  display: block;
}
.flip-title .back {
  display: none;
}
.flip-title:hover .front {
  display: none;
}
.flip-title:hover .back {
  display: block;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use $(this).find(...).

$(".flip-tile").hover(function() {
    $(this).find(".front").hide()
    $(this).find(".back").show()},
    function() {
    $(this).find(".back").hide()
    $(this).find(".front").show()
});

Comments

1

Please take a look on https://api.jquery.com/class-selector/

I.e.

<script>
$( ".myclass.otherclass" ).css( "border", "13px solid red" );
</script>

The example will apply the border style to any .myclass.otherclass items along the HTML

good luck!

1 Comment

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.
0

Try this:-

$(".flip-tile").hover(function() {
     $(this).find(".front").hide()
     $(this).find(".back").show()},
    function() {
      $(this).find(".back").hide()
     $(this).find(".front").show()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flip-tile">
        <div class="front">
            <div class="project-tile primary-color col-md-4 col-xs-12">
                <img class="tile-img" src="../static/img/first.png">
                <div class="tile-text">
                    <h4><span class="light">Front side</span></h4>
                </div>
            </div>
        </div>
        <div class="back" style="display:none;">
            <div class="project-tile secondary-color col-md-4 col-xs-12">
                <div class="tile-text">
                    <h4><span class="light">Back side</span></h4>
                </div>
            </div>
        </div>
    </div>

    <div class="flip-tile">
        <div class="front">
            <div class="project-tile primary-color col-md-4 col-xs-12">
                <img class="tile-img" src="../static/img/first.png">
                <div class="tile-text">
                    <h4><span class="light">Front side</span></h4>
                </div>
            </div>
        </div>
        <div class="back" style="display:none;">
            <div class="project-tile secondary-color col-md-4 col-xs-12">
                <div class="tile-text">
                    <h4><span class="light">Backside</span></h4>
                </div>
            </div>
        </div>
    </div>

1 Comment

Thanks guys! I must have been using the find() wrong when i tried a similar solution earlier!

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.