0

I've added a webpart to sharepoint and added a widget using javascript. The javascript displays weather information and a few links. When i view the source of the page I cannot see any of the content of the widget but only the controlling parameters and the javascript. I always thought when viewing page source it would show everthing the page renders. Then when i right click the widget I can see the source contents of the widget. See code below.

When I goto debug mode in IE (f9) I can select some to the weather widget classes and Id's. I want to hide the "helplink" part within the widget and have tried the code below without success. The alert displays but I dont nothing gets hidden


alert("hello");

document.getElementById(helplink).style.visibility="hidden";


Here is partial code of widget. i want to hide "helplink"

<section id="mainContainer" class="box displaybottom posrel">
        <article id="nonmap" class="box displaybottom">
            <div id="location"><span></span></div>
            <div id="date"></div>
            <section id="content"><div id="icon"></div></section>
        </article>
        <div id="maps" class="box displaybottom"></div>
    </section>
    <footer id="bigfooter" class="box displaybottom posrel" >
        <div id="footer" class="">
            <div id="moredetail" style="display:none;"><a id="helplink" href="http://www.metoffice.gov.uk/services/weather-widget" target="_blank"></a>&nbsp;<a href="#" id="optionslink"></a>&nbsp;<a id="moredetaillink" href="" target="_blank"></a></div>
            <div id="copyright"><span id="copyrightsymbol"></span><a href="http://www.metoffice.gov.uk/corporate/legal/tandc#widget" title="Weather widget terms of use" target="_blank"></a></div>
        </div>
        <div id="advert"></div>
    </footer>
1

Put quotes around the element ID, like this:

document.getElementById("helplink").style.visibility="hidden";

View source will not show you dynamically rendered content, only the original source of the page as it left the server. To see dynamic content you'll have to use the F12 tools, and you might have to hit the little "refresh" button on the HTML tab.

If your "helplink" element is rendered dynamically you'll have to defer calling it until that dynamic content is loaded. Usually this is done in a window loaded event or a jQuery ready() handler. In your code you'll need to figure out the right place to put it.

  • Hi Tried the quotes and get error SCRIPT5007: Unable to get value of the property 'style': object is null or undefined I think I'm not targeting the element. I rememeber using "#s4-workspace" for another purpose. Could this be the problem? – Raj Chahal Jul 30 '13 at 7:59
  • your getElementById() is not finding the helplink element. You need to call it AFTER the widget loads. If you just put it in the global scope it will fail with the error you mentioned. – Derek Gusoff Jul 30 '13 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.