Search code examples
jquerytoggledashcode

How can I toggle the display of an element remotely? I will not have server access


Can anyone recommend the easiest way to toggle the display of an element remotely? I won't have access to the server so I was wondering if there is a way to remotely toggle the display of an element, in this case from solid to faded? I'm using dashcode and I don't know how cross domain policy impacts this.

   $(document).ready(function(hideStuff) {
   $('.image2_template').css({ 'opacity' : 0.1 });
   $('.text3_template').css({ 'opacity' : 0.1 });

Solution

  • I’m doing the same sort of thing in a Dashcode widget… I have a version.js file on the widget’s website, and if that file reports a newer version number than what the user’s using, they’ll see a prompt to update. What I did was basically this:

    1. Set the element to its default state (“solid” for you, I guess) as your widget initializes.
    2. Using an AJAX query, get the JSON file from the server. (You can do this easily with jQuery.)
    3. In the callback function for the AJAX query, check whatever you need to; if your display needs to change, then go ahead and do

      document.getElementById("image2_template").style.setProperty("opacity", 0.1);
      

      or whatever you need to do.

    Note that you will need access to some server somewhere in order for this to work.