Problem with jquery script on firefox works fine on IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alvaro Louzada
    New Member
    • Jan 2011
    • 3

    Problem with jquery script on firefox works fine on IE

    i m using this script to expand a DIV

    Code:
    function ShowDiv(Div-id) {
    if (false == jQuery(Div-id).is(':visible')) {
    jQuery(Div-id).show(250);
    }
    else {
    jQuery(Div-id).hide(250);
    }
    }
    
    //and the link is like this
    
    onclick="ShowDiv(Div-1)"
    
    onclick="ShowDiv(Div-2)"
    on firefox giveme a erro Div-1 is not defined
  • Samishii23
    New Member
    • Sep 2009
    • 246

    #2
    First off, you can not use the hyphen symbol (-) as apart of a variable name. Its a reserved character for subtraction. That is most likely why Firefox is giving the variable not declared error.

    Plus: This may be a lot easier:
    Code:
    function ShowDiv(id) {
      $(id).show();
      // and for hiding
      $(id).hide();
      }
    Also, jQuery provides the toggle() function which automatically checks to see if the element matched is hidden or shown and will show or hide the element proper.
    Code:
    $(id).toggle();

    Comment

    • Alvaro Louzada
      New Member
      • Jan 2011
      • 3

      #3
      with the last solution dont work..

      let me put my fixed code but just work on IE

      Code:
      function ShowDiv(Div_id) {
      if (false == jQuery(Div_id).is(':visible')) {
      jQuery(Div_id).show(250);
      }
      else {
      jQuery(Div_id).hide(250);
      }
      }
      then i have

      Code:
      //link 
      
      onclick="ShowDiv(Div_1)" 
      
      // the i have the oculted div
      <div class="commentformBlock Light11 Orange1" id="Div_1" style="display: none;">
      On IE on the first click shows div, if i click again fade div

      on firefox not works.

      Comment

      • Samishii23
        New Member
        • Sep 2009
        • 246

        #4
        Try replacing jQuery() with $(), and report back. If that doesn't work I need to know what error the browser gives specifically.

        Comment

        • Alvaro Louzada
          New Member
          • Jan 2011
          • 3

          #5
          i m jQuery instead of $ becuz there is alot of another jquery functions but i fixed: there is the code works on ie, firefox, chrome like a charm

          Code:
          function ShowDiv(Div_id){
          	var div = Div_id;
          	if(jQuery('#'+ div).is(':hidden')){
          
          	jQuery('#'+ div).show(250);   
          	}  
          	else
          	{   
          	jQuery('#'+ div).hide(250);  
          	}
          	}

          Comment

          Working...