Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #14853

Re: Why is .click() not effective and requires us to press on Refresh?

From "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com>
Newsgroups comp.lang.javascript
Subject Re: Why is .click() not effective and requires us to press on Refresh?
Date 2012-07-04 14:36 +0200
Organization Sebastien Vauban
Message-ID <80wr2jbt4v.fsf@somewhere.org> (permalink)
References <807guldukp.fsf@somewhere.org> <4ff335de$0$6179$ba4acef3@reader.news.orange.fr>

Show all headers | View raw


Hello SAM,

SAM wrote:
> Le 03/07/12 12:09, Sebastien Vauban a écrit :
>> I've made up an example of what I'm trying to achieve in
>> http://jsfiddle.net/svajquery/ttVUA/4/.
>>
>> I have "tabified" all H2, and want to click on a link in the first tab
>> ("Dashboard") and want to be redirected on the right place of the second tab
>> ("Tasks").
>>
>> While the URL is correctly displayed in the address bar of the browser (at
>> least when testing those files in a real browser environment), the .click() is
>> not effective.
>
> the function click() can't work with a link (in "normal" JS) it was made for
> buttons of forms (submit for instance)

OK. Though, I'm not sure to fully understand, as it is clear that it does work
in the following lines:

--8<---------------cut here---------------start------------->8---
          // set the right tab as current
          $('#tabs > li a[href="#' + tabname + '"]').click();
      }
      else {
          // set the first tab as current (on page load)
          $('#tabs > li a').filter(':first').click();
--8<---------------cut here---------------end--------------->8---

>> I must press on the Refresh button to really go where I want to.
>>
>> Do you have any explanation?  I surely miss something!
>
> <a href="#sec-2-2" onclick="showMe('Task')">Do that tomorrow</a>
>
> You probably only need to show the good div (and hide the other one)
> the link will naturally run to the anchor 'sec2-2' (basic html)

Here, you come up with a function `showMe' that I did not yet have...

I've managed to get this code for it:

--8<---------------cut here---------------start------------->8---
function showMe (tab) {
    alert("tab = " + tab);

    // highlight the selected tab in the menu, and dim all others
    $('#tabs > li').removeClass('selected');
    $('#' + tab).parent('li').addClass('selected');

    // show the contents of the selected tab, and hide all others
    $('.outline-2').hide();
    $('#' + tab).parent('.outline-2').show();

    // don't follow the link
    return false;
}
--8<---------------cut here---------------end--------------->8---

With it, the following link:

    <a href="#sec-2-2" onclick="showMe('sec-2')">Do that tomorrow</a>

is correctly followed; I mean: "Tasks" tab is opened, and the page is
positioned on screen as I expect it.

Though, my problem is that the pages I'm working on are completely generated
HTML. Hence, it is difficult to imagine having the correct call (to the
correct tab) in `onclick'. Moreover, in real-life examples, there won't be
just one tab with tasks, but many different ones: a "Tasks" tab, an "Issues"
tab, and so on. And the purpose from the "Dashboard" tab is to jump where
appropriate, upon clicking.

I have a gut feeling that there must be a simpler way -- however, well beyond
my JS debugging experience (simply above what I know from JS). Why do I think
that? Because the first snippet of code (here above) works well with such
links:

- file.html sets the first tab as the current one

- file.html#sec-2 (or file.html#tasks, if I would have given a more
  significant name) sets the second tab as the current one (after an eventual
  click on the browser's refresh button)

- so does file.html#sec-2-1 (that is a link inside the second tab), with a
  browser refresh

So, such links (to individual tasks) are essentially correctly followed... but
only after a browser refresh. That's the stumbling block.

Does this help (for helping me ;-))?

Thank you very much in advance for your help!

Best regards,
  Seb

-- 
Sebastien Vauban

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why is .click() not effective and requires us to press on Refresh? "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> - 2012-07-03 12:09 +0200
  Re: Why is .click() not effective and requires us to press on Refresh? Gregor Kofler <usenet@gregorkofler.com> - 2012-07-03 14:26 +0200
    Re: Why is .click() not effective and requires us to press on Refresh? "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> - 2012-07-04 11:43 +0200
      Re: Why is .click() not effective and requires us to press on Refresh? SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-07-04 12:13 +0200
        Re: Why is .click() not effective and requires us to press on Refresh? "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> - 2012-07-04 14:37 +0200
      Re: Why is .click() not effective and requires us to press on Refresh? Gregor Kofler <usenet@gregorkofler.com> - 2012-07-04 13:58 +0200
        Re: Why is .click() not effective and requires us to press on Refresh? "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> - 2012-07-05 09:23 +0200
          Re: Why is .click() not effective and requires us to press on Refresh? Gregor Kofler <usenet@gregorkofler.com> - 2012-07-05 14:47 +0200
        Re: Why is .click() not effective and requires us to press on Refresh? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-07-05 16:48 +0200
  Re: Why is .click() not effective and requires us to press on Refresh? SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-07-03 20:11 +0200
    Re: Why is .click() not effective and requires us to press on Refresh? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-07-03 18:25 +0000
      Re: Why is .click() not effective and requires us to press on Refresh? Gene Wirchenko <genew@ocis.net> - 2012-07-03 13:16 -0700
        Re: Why is .click() not effective and requires us to press on Refresh? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-07-03 21:10 +0000
      Re: Why is .click() not effective and requires us to press on Refresh? SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-07-04 09:49 +0200
        Re: Why is .click() not effective and requires us to press on Refresh? SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-07-04 10:18 +0200
    Re: Why is .click() not effective and requires us to press on Refresh? "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> - 2012-07-04 14:36 +0200
      Re: Why is .click() not effective and requires us to press on Refresh? "Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> - 2012-07-04 15:15 +0200

csiph-web