risha riss
risha riss

Reputation: 47

Adding css to jquery children elements

I am trying to make a popup which would display on mouse hover by using jquery and some css. The code works as it should, however i can't add any CSS to the child elements of the popup window for some reason.

Here's the jquery code:

  $(document).ready(function(){

    var $popup = $('.popup');
    $('area').on({
      mouseover : function(e){
        var $this = $(this),
            $obj = $('#'+$this.prop('alt'));
        $popup.text($obj.text()).css({
          top: '90%',
          left: '24.8%',
          color: 'orange',
          }).show();
      },
      mouseout: function(){
        var $this = $(this),
            $obj = $('#'+$this.prop('alt'));          
        $popup.hide(0).empty();
      }
    });
    });

And here's the popup html code containing what is displayed in the popup. Nothing happens when i try to add the css to the classes displayed inside popup.

<div class="stanovanje" id="n1s1">
<h2>Področje 1</h2>
  <div class="koda">Koda:<br><p>1-12-123-S1</p></div><div class="tip">Tip:<br><p>A1</p></div><div class="povrsina">Površina:<br>84.24m</div> <div class="vrsta">Vrsta:<br>z balkonom/teraso</div><div class="cena">Cena:<br>120000€</div>
</div>
<div class="stanovanje" id="n1s2">
  <div class="koda">Koda:<br><p>1-12-123-S2</p></div><div class="tip">Tip:<br><p>A2</p></div><div class="povrsina">Površina:<br>74.24m</div> <div class="vrsta">Vrsta:<br>z balkonom/teraso</div><div class="cena">Cena:<br>140000€</div>
</div>
<div class="popup"></div>

Thanks for reading and all the answers!

Upvotes: 0

Views: 294

Answers (2)

Mujtaba Haider
Mujtaba Haider

Reputation: 1650

top or left props would work with positioned elem Update 2: I hope It will work this way

JS

var $popup = $('.popup');   
$popup.html($obj.html());
$('.popup div').css({
    top: '90%',
    left: '24.8%',
    color: 'orange',
position: 'relative' //absolute
});
$popup.show();

Upvotes: 1

Jonathan
Jonathan

Reputation: 773

You have wrong code too, you need to remove last comma:

$popup.text($obj.text()).css({
    top: '90%',
    left: '24.8%',
    color: 'orange',
}).show();

Should be:

$popup.text($obj.text()).css({
    top: '90%',
    left: '24.8%',
    color: 'orange'
}).show();

Upvotes: 0

Related Questions