Hiber Natus
Hiber Natus

Reputation: 25

How to change style of div #id that contain selected .class

I'm trying to change style of div #info_frame that contain class nazwa_klasy_display and I can't fix it.

$('.box').mouseenter(function() {       
   //show up scores
   $( this ).children( '.scores' ).css( 'display', 'block' );

   nazwa_klasy = $( this ).attr('class').split(' ')[1];

   nazwa_klasy_display = nazwa_klasy.split('_')[1];
   if ($('#info_frame').has(nazwa_klasy_display)) 
   {
      $('#info_frame .'+nazwa_klasy_display).style.display ="block";    
   }
});

Upvotes: 0

Views: 123

Answers (3)

Karthick Kumar
Karthick Kumar

Reputation: 2361

$("#info_frame").hasClass('.'+nazwa_klasy_display).css('display','block');

try this

Upvotes: 0

ddavison
ddavison

Reputation: 29052

If my understanding is correct, you are looking for a <div> that has the id of info_frame and the class of nazwa_klasy_display then you do need to fix your CSS selector. you have a space in there when it shouldn't be.

$('#info_frame.'+nazwa_klasy_display)

the selector #info_frame .[nazwa_klasy_display] will be looking for anything that has the class nazwa_klasy_display that is a descendant of *#info_frame

Upvotes: 0

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123397

you're mixing jQuery with plain Js:

either you use

/* chain a jQuery method, e.g. show()  */
$('#info_frame.'+nazwa_klasy_display).show()

or

/* access to the dom node before using plain js */
$('#info_frame.'+nazwa_klasy_display).get(0).style.display = "block";  

Upvotes: 1

Related Questions