0

I have a "feedback widget" that i want to hide for low resolution screens. my problem is that it's injecting the following code right after <body> and no metter what i try i can't hide reformal_tab element

<a id="reformal_tab" href="http://domain.com" onclick="Reformal.widgetOpen();return false;" onmouseover="Reformal.widgetPreload();" onmouseout="Reformal.widgetAbortPreload();"><img alt="" src="domain.com/tab.png"></a>

what i've tried

<script>
        $('reformal_tab').hide();
        $('#reformal_tab').hide();
</script>

this is the actual widget if that can help http://reformal.ru/

the code:

<script type="text/javascript">
$(function() {
    $('#reformal_tab').hide();
});

    var reformalOptions = {
        project_id: 93459,
        project_host: "domain.com",
        tab_orientation: "left",
        tab_indent: "50%",
        tab_bg_color: "#F05A00",
        tab_border_color: "#FFFFFF",
        tab_border_width: 2
    };

    (function() {
        var script = document.createElement('script');
        script.type = 'text/javascript'; script.async = true;
        script.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'media.reformal.ru/widgets/v3/reformal.js';
        document.getElementsByTagName('head')[0].appendChild(script);
    })();
</script>

you can see it live here http://jsfiddle.net/PQsQq/2/

5
  • is the html appearing before the javascript in your page? Commented Mar 28, 2013 at 0:14
  • What if you wrap it in $(function () {})? Commented Mar 28, 2013 at 0:14
  • It may be injecting the reformal_tab element after you are attempting to call hide. $('#reformal_tab').hide(); should do it. Commented Mar 28, 2013 at 0:15
  • i put the hide(); code just before </body> Commented Mar 28, 2013 at 0:20
  • load the jquey in head tag and put the hide() after body tag in script tag. Commented Mar 28, 2013 at 0:56

3 Answers 3

3

The second call is the valid one. The # references the element by id.

$('#reformal_tab').hide();

You'll also need to call it when the document is ready.

$(function() {
    $('#reformal_tab').hide();
});

Why don't you just make it hidden when you inject it, and then you can show it for higher res screens?

<a id="reformal_tab" style="display:none;" href="http://domain.com" ...

Then somewhere in your script..

if(highResolution) {
  $("#reformal_tab").show();
}
Sign up to request clarification or add additional context in comments.

5 Comments

@teslasimus - Ok, made some changes.
This should definitely work jsfiddle.net/PQsQq delete the javascript or change .hide to .show. Check that you've referenced your jquery javascript correctly?
@Mal - The OP's issue is the HTML is injected into the DOM, so hide() is called before the element is injected, and therefore doesn't exist at the time.
@Aesthete not sure if it's posible, please check the "widget code"
@Aesthete Ahh! Okay sorry I didn't pick up on this.
0

Why not just remove it?

$('#reformal_tab').remove();

Comments

0

If the element is injected with javascript, it's probably inserted dynamically after DOM ready. The solution is rather simple, in your CSS do:

#reformal_tab {display: none;}

3 Comments

@teslasimus - The element is inside an iFrame, which you don't have access to. Just set it in CSS, and it seems you need !important to override the styles -> FIDDLE
but how can i implement it with jquery? i want to show it acording to resolution.
@teslasimus - You can't really, but you can use CSS media queries to make it resolution dependent, and that would be the right way to do it, as you don't need jQuery for this.

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.