php - Can't use .css to change display from none to block -


here css:

#optionhotel{     display:none; } 

here javascript:

function cb1(type){     switch(type){         case "hotel":             alert("hotel");             $("#optionhotel").css("display","block");             break;     } } 

here html:

<div id="optionhotel"> element in here</div> 

start script in 'head tag':

<?echo ' <script>window.onload = cb1("'.$ordertype.'");</script> '?>  <!--css--> <link href="../../css/navigate.css" rel="stylesheet"/> <link href="../../css/reservation.css" rel="stylesheet"/> 

passing data php js ok because have checked in switchcase

with alert() it's ok don't know why .css display block doesn't work

please advice, thank in advance

your code:

<script>window.onload = cb1("'.$ordertype.'");</script> 

will call cb1() function , try assign result window.onload handler. see alert because function run, because runs inside head of document document body has not yet been parsed script can't find element.

you need assign actual function handler, function run onload , @ point call cb1():

<script>window.onload = function() { cb1("'.$ordertype.'"); };</script> 

or, since using jquery, , assuming don't want wait images load before calling function, use document ready handler:

<?echo ' <script>   $(document).ready(function() {      cb1("'.$ordertype.'");   }); </script> '?> 

...or move script end of body , call function directly:

<?echo ' <script>cb1("'.$ordertype.'");</script> '?> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -