1

I have 2 questions

  1. I am using the hashchange plugin .... so I want to know would a function as below, be called everytime a hashchange occurs... because I have something like that in my code and the code function apparently doesnt seems to be called

    $(document).ready(function()
    {
        // function here
    });
    
  2. On the other have if I remove the hashchange as in If i make http://abc.com/a.htm#http://abc.com/b.htm as http://abc.com/b.htm the code works fine

the problem is the structure of my pages is a bit different .... here is the fiddle with the page structure that explains on a higher level what I am trying to achieve jsfiddle.net/vBKWd/9 ... on hash change jus the div c on my page 1 gets replaced by page 2 and vice versa .... and the js function that I have shown below is getting called only once and not after hashchange

Or is therre any way I can bind the function with the div so that whenever the div is replace the function get called?

3
  • your example doesn't convey anything. maybe add some more details? Commented Jun 30, 2011 at 4:56
  • can we see the code of your function? Commented Jun 30, 2011 at 4:58
  • @amosrivera the function works perfectly fine ... the problem is that it is called once when the page is loaded but not on hash change .... Commented Jun 30, 2011 at 5:09

3 Answers 3

3

No, a ready handler is only called on document ready, not on hash change. You should use the hashchange event for that, instead:

$(window).hashchange(function () {
    // function here
});

Sample: http://jsfiddle.net/vBKWd/2/

Sign up to request clarification or add additional context in comments.

8 Comments

"didnt work"... could you be a bit more descriptive? Maybe produce a JSFiddle example of it not working? You're saying that the code in place of // function here is not called on hashchange, or does "didnt work" mean something else?
@Domenic ... is therre any way I can bind the function with the div so that whenever the div is replace the function get called?
I don't understand; are you using the comments to ask an entirely separate question? I'd suggest asking a new question for that, and marking this one as answered if it has been, or deleting it if you don't care about the answer.
@Domenic sorry for not being descriptive ... yes the //function here is not called on hash change ..... and I didn't ask another question in the comment ... the reason for asking that was that the hashchange function replaces div so if you might be aware of any function that might trigger on div change that would do the job .... I would get right on making a fiddle for this ... anyways thanks for the effort +1
there is no as such function which triggers om div change..you can make your own using trigger(function1()), existing jquery function.
|
0

In document ready wirte code below

$(window).bind('hashchange', function () {
                 //code here
});

Comments

-1

use live in this case

$(document).ready(function()
{   
   $(selector).live(hashchange, function(){
    // your code goes here

    });
});

2 Comments

the problem is the structure of my pages is a bit different .... here is the fiddle with the page structure that explains on a higher level what I am trying to achieve jsfiddle.net/vBKWd/9 ... on hash change jus the div c on my page 1 gets replaced by page 2 and vice versa .... and the js function that I have shown below is getting called only once and not after hashchange ... does that help?
ReferenceError: hashchange is undefined. Also, live has no effect with applied to "hashchange", and the hashchange event cannot be applied to non-window objects. -1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.