Div wrap entire page

8 views
Skip to first unread message

fugee ohu

unread,
Mar 25, 2018, 12:38:30 PM3/25/18
to Ruby on Rails: Talk
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

Walter Lee Davis

unread,
Mar 25, 2018, 2:28:41 PM3/25/18
to rubyonra...@googlegroups.com
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 <fuge...@gmail.com> 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 rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> 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 all
Reply to author
Forward
0 new messages