By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,023 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,023 IT Pros & Developers. It's quick & easy.

Problem with jquery script on firefox works fine on IE

P: 3
i m using this script to expand a DIV

Expand|Select|Wrap|Line Numbers
  1.  
  2. function ShowDiv(Div-id) {
  3. if (false == jQuery(Div-id).is(':visible')) {
  4. jQuery(Div-id).show(250);
  5. }
  6. else {
  7. jQuery(Div-id).hide(250);
  8. }
  9. }
  10.  
  11. //and the link is like this
  12.  
  13. onclick="ShowDiv(Div-1)"
  14.  
  15. onclick="ShowDiv(Div-2)"
  16.  
  17.  
  18.  
on firefox giveme a erro Div-1 is not defined
Jan 10 '11 #1
Share this Question
Share on Google+
4 Replies


Samishii23
100+
P: 246
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:
Expand|Select|Wrap|Line Numbers
  1. function ShowDiv(id) {
  2.   $(id).show();
  3.   // and for hiding
  4.   $(id).hide();
  5.   }
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.
Expand|Select|Wrap|Line Numbers
  1. $(id).toggle();
Jan 10 '11 #2

P: 3
with the last solution dont work..

let me put my fixed code but just work on IE

Expand|Select|Wrap|Line Numbers
  1. function ShowDiv(Div_id) {
  2. if (false == jQuery(Div_id).is(':visible')) {
  3. jQuery(Div_id).show(250);
  4. }
  5. else {
  6. jQuery(Div_id).hide(250);
  7. }
  8. }
  9.  
then i have

Expand|Select|Wrap|Line Numbers
  1. //link 
  2.  
  3. onclick="ShowDiv(Div_1)" 
  4.  
  5. // the i have the oculted div
  6. <div class="commentformBlock Light11 Orange1" id="Div_1" style="display: none;">
  7.  
On IE on the first click shows div, if i click again fade div

on firefox not works.
Jan 10 '11 #3

Samishii23
100+
P: 246
Try replacing jQuery() with $(), and report back. If that doesn't work I need to know what error the browser gives specifically.
Jan 10 '11 #4

P: 3
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

Expand|Select|Wrap|Line Numbers
  1. function ShowDiv(Div_id){
  2.     var div = Div_id;
  3.     if(jQuery('#'+ div).is(':hidden')){
  4.  
  5.     jQuery('#'+ div).show(250);   
  6.     }  
  7.     else
  8.     {   
  9.     jQuery('#'+ div).hide(250);  
  10.     }
  11.     }
  12.  
Jan 10 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.