2

I created a Firefox add-on for myself to view the button at http://www.reddit.com/r/thebutton. All I want is for the button to be the only element shown. All I want is for the button form to be the only form shown. This is the only way I could find to isolate the button using jQuery. I feel like its the wrong way to do it and was curious if there was a proper way.

$('#header').remove();
$('.side').remove();
$('.footer-parent').remove();
$('#siteTable').remove();
$('#progressIndicator').remove();
$('.debuginfo').remove();
$('section').remove();
$('.content').css({"margin" : "auto"});
2
  • Well if it's for yourself then as long as it works then it is good to go. You can also do .hide() on the elements and should produce the same result Commented May 6, 2015 at 19:55
  • I was just thinking if they added one extra section to the page I would have to go back and add a new hide line and it seems wrong to have to do that. Commented May 6, 2015 at 20:01

2 Answers 2

1

You can do this

$('.thebutton-form').prependTo('body');
$('body').children().not('.thebutton-form').hide(); // or remove()

This will attach the button to the beginning of the document and hide or remove the rest of the stuff

This solution does not depend on the #header being there.

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

Comments

1

You could do something like this

$('body').prepend($('.thebutton-form'));
$('body').children(':not(.thebutton-form)').hide();

You could also use .remove();.

BTW not entirely sure if it is cross browser or not.

First line moves the form to be a direct child of the body. Second line hides / removes all other elements in the body that are not the form.

No idea why i used insertAfter instead of prepend /append but I fixed it.

2 Comments

Actually, what you posted before $('.thebutton-form').insertBefore('#header'); $('body').children(':not(.thebutton-form)').hide(); worked but when I try this one all it does is have the words ".thebuttonform" in the panel.
Yea I forgot to do .prepend($('.thebutton-form'));. I corrected my solution

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.