• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Accessing elements after DOM fired.

#1
Hi,

I am writing some code for the front end of my site. I'm forced to use AJAX as our page loading method. We use anchors as hooks to detect what page the user was on (not sure if that's needed).

I'm having some problems with a tags after the DOM is loaded. So if you click onto another page which is loaded from AJAX it doesn't take the _initPages(); route.

Now, I know what you are going to say, just run that function every time I detect a hash change. I don't want to do that.

What I'm asking is there any jQuery function that looks at the DOM on click instead of at the time of the function is ran. Errr, confusing.

Thanks,

Code:

Code:
__construct: function()
{             
           
            this._initPages();
           
            $(window).bind('hashchange', function()
            {
                   
                mySite._detectHash();
               
                if( mySite._hash )
                { 
                   
                    mySite._loadPage(mySite._hash); 
                   
                }             
                   
            });
           
            $(window).trigger("hashchange");
           
            this._init();     
           
        },
 
        _initPages: function()
        {
         
         
            $( 'a:not(.noAjax)' ).on( 'click', function( )
            {
         
                window.location = '/#!/' + $( this ).attr('href');
               
                return false;
               
            } );
           
        }
 
#3

Adam Howard

Well-known member
#7
I gave a quick look over and from what I can see.... Nicely done. (y)

I'm wondering if maybe the conflict lies else where (conflict with something outside your code) or maybe we're both (you and me) missing something here.

I'd suggest 2 names in who I believe you can trust help debug this issue further (you should get in contact with one of them)
I also suggest these two because from the code you gave me, its clear this is part of a larger project. And I'm kind of limited on the time it would take to review the whole (larger picture).

But from what I could see... The code looked clean to me and should be loading smoothly. So clearly we're both missing something.
 
#8
I gave a quick look over and from what I can see.... Nicely done. (y)

I'm wondering if maybe the conflict lies else where (conflict with something outside your code) or maybe we're both (you and me) missing something here.

I'd suggest 2 names in who I believe you can trust help debug this issue further (you should get in contact with one of them)
I also suggest these two because from the code you gave me, its clear this is part of a larger project. And I'm kind of limited on the time it would take to review the whole (larger picture).


But from what I could see... The code looked clean to me and should be loading smoothly. So clearly we're both missing something.
If you are in direct contact with them could you point them in this direction (give them the code if you need). I'm fairly new around here.