jerrygarciuh
jerrygarciuh

Reputation: 22018

jQuery syntax for targeting div of class inside div of another class

Two jQuery questions:

1) Given this HTML structure

<div id="tipper" class="tiplink"><a href='test.html' >Link Text</a>
<div id="tip" class="tipdiv">This is the tool tip text.</div>
</div>

How can I alter these to work on classes so that that when a div of class .tiplink is moused over the div of class .tipdiv inside it is targeted?

  $(document).ready(function(){
    $('#tipper').mouseover(function() {
      $('#tip').clearQueue().show(0);
    });

    $('#tipper').mouseleave(function() {
        setTimeout( function(){
        $('#tip').hide(0);
      },20000);
    });

2) Without using a text input is it possible to select all the text in .tipdiv on click?

Upvotes: 0

Views: 1470

Answers (2)

scrappedcola
scrappedcola

Reputation: 10572

$('div.tiplink').mouseover(function() {
      $(this).find('div.tipdiv').clearQueue().show(0);
    });

and for the click

$('div.tiplink').click(function() {
     var text =  $(this).find('div.tipdiv').text();
    });

Upvotes: 2

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

Use hover(). It's built for that.

$('#tipper').hover(function(){...on state..},function(){...off state...})



$('#tipper').click(function() {
  var myText = $('.tipdiv').html();
   alert(myText)
}

Upvotes: 0

Related Questions