Div wrap entire page

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Div wrap entire page

fugee ohu
I tried to div wrap a page and replace its content with a link to # so I could click the link to make the whole page appear with jquery Should I be able to do that regardless what's on the page, cause it doesn't seem to wanna work

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4b693687-562c-47fe-ac3e-4e36bdc26194%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Div wrap entire page

Walter Lee Davis
When JavaScript does not work, you need to immediately suspect whether your rendered HTML is valid, and whether the HTML exists in the browser's "mind" at the moment it is evaluated. Open the Developer Tools console in your browser, click on the element, and look at the result of your request, if any. If you don't see a request, then suspect that your JavaScript is not properly bound to the page element you think it is. If you are rendering this JS with the asset pipeline, then remember that your script will appear (in source order) before the HTML it refers to, so you MUST use lazy-evaluation techniques to find the thing you want to listen to, otherwise your listener will not be bound to an element, and it will fail silently. In jQuery, that would be $(document).on('click', 'some CSS selector', function(){ .. do something here .. }); If you have inlined your script below the HTML it refers to, then you have a different problem, and without an example of the rendered HTML to look at here, I can only tell you where to start poking.

You should not need a link; if you have an ID on the div you want to "re-fill", then just a click on that div should be enough.

$(document).on('click', '#some_div', function(){
  $(this).load('/path/to/route');
});

path/to/route would be whatever URL you would hit in your app to get the content you want to use to re-fill the div. The 'load' method is a shortcut for $('#elm').html = $.get('some url').

If you do have a link to #, then remember that link will be followed unless you stop it in your click handler. You don't need to worry about that when you bind a regular click handler to a non-link element.

Walter

> On Mar 25, 2018, at 12:38 PM, fugee ohu <[hidden email]> wrote:
>
> I tried to div wrap a page and replace its content with a link to # so I could click the link to make the whole page appear with jquery Should I be able to do that regardless what's on the page, cause it doesn't seem to wanna work
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4b693687-562c-47fe-ac3e-4e36bdc26194%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/769712AE-1D31-4880-8349-1BF4386DAB7F%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.