+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Javascript change style attribute of span

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Javascript change style attribute of span

    So everyone that has a Facebook knows that there is a feature where you can hide content from 'non-members' of a group/fan page. I, if not many, have found a way to bypass this. Since Facebook does not actually keep the content away from 'non-members' rather it just hides the content with some cheap styling.
    Code:
    visibility:hidden;
    so I just use FireBug and delete that attribute so I dont actually have to join the group.

    Now opening FireBug each time and looking for the content is not a hassle but can be simplified. I was thinking of javascript and changing the style to visible.
    Code:
    document.*.style.visibility = "visible";
    but then the span tags do not always have an id or class attached to define them. so i came across this.
    http://robertnyman.com/2006/01/23/mo...tsbyattribute/
    which basically allows you to search by attribute and its properties.

    the only problem is. I cant get the javascript to work properly. anybody know what im doing wrong.
    i would post up the code i was working with, but it might just confuse you all, because i did a ****ty job.


    here is the template for most of these pages
    Code:
    <div style="position: relative; overflow: hidden;">
    <span style="background: none repeat scroll 0% 0% white;">
    Un-Hiden Content
    
    <span style="visibility: hidden;">
    /*********
    * Hidden Content
    *********/
    </span>
    <span style="visibility: visible;"></span>
    </span>
    </div>
    Last edited by diabolo; 04-26-2010 at 08:56 PM.

  2. #2
    essellar's Avatar
    essellar is online now Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,152

    Re: Javascript change style attribute of span

    Why not just use getElementsByTagName() and cycle through the collection?
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Javascript change style attribute of span

    how would I cycle? because I have no javascript experience

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Javascript change style attribute of span

    Code:
    var spanArray = document.getElementsByTagName('span');
    var number_spans = spanArray.length ;
    
    for( var i = 0; i < number_spans ; i++ ){
    
     var target = spanArray[ i ] ;
    
    // do something with target like set visibility
    
    }
    Nothing is always absolutely so.

  5. #5
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Javascript change style attribute of span

    thank you descalzo!
    here is what i got so far. the link to show the span tag works but Im having difficulty transforming the javascript script into something I can bookmark and put into the URL. (http://webdevelopmenttutorials.com/e...otheurlbox.php)
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    	<title>Dynamic CSS Properties</title>	
    	<script language="JavaScript">
    	function change(){
    	//document.getElementById("box1").style.visibility = "visible";
    	
    	var spanArray = document.getElementsByTagName('span');
       var number_spans = spanArray.length ;
       for( var i = 0; i < number_spans ; i++ ){
       var target = spanArray[ i ] ;
          // do something with target like set visibility
          target.style.visibility = "visible";
       }
       }
       function change2(){
          var spanArray=document.getElementsByTagName('span');var number_spans=spanArray.length;for(var i=0;i<number_spans;i++){var target=spanArray[i];target.style.visibility="visible";}
       }
    	</script>
    </head>
    
    <body>
    <a href="javascript:change2();">Change</a>
    <br />
    <div style="position: relative; overflow: hidden;"><center>
    <br><br>
    <font size="5" color="blue">
    
    1. just press the <img src="http://up203.siz.co.il/up1/jw2k4az1imny.jpg"> button on the top to see the picture i promise you its so funny!!!!:
    <br><br><br>
    
    <span style="background: none repeat scroll 0% 0% white;"><span style="visibility: hidden;">
    
    <a onmousedown="UntrustedLink.bootstrap($(this), &quot;77a0d&quot;, event)" rel="nofollow" target="_blank" onclick="(new Image()).src = '/ajax/ct.php?app_id=4949752878&amp;action_type=3&amp;post_form_id=3917211492ade40ee468fbe283b54b3b&amp;position=16&amp;' + Math.random();return true;" href="http://thebigbrotherisrael.blogspot.com/2010/04/all-family-guy-characters-in-real-life.html">Press here to see the picture!!!</a>
    
    </span><span style="visibility: visible;"></span></span></font></center></div>
    
    </body>
    </html>
    I have tried
    Code:
    javascript:var spanArray=document.getElementsByTagName('span');var number_spans=spanArray.length;for(var i=0;i<number_spans;i++){var target=spanArray[i];target.style.visibility="visible";};
    but it doesnt do anything
    Last edited by diabolo; 04-27-2010 at 03:55 PM.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Javascript change style attribute of span

    Since you're already using Firefox, install Greasemonkey and write it as a Greasemonkey script. An additional advantage is it will get invoked automatically whenever you visit a facebook page.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Javascript change style attribute of span

    I will definitely go and try that misson.
    But what about IE users or Safari users? so im still looking for a javascript method

  8. #8
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Javascript change style attribute of span

    Just to let you know that code works just fine as it is. To allow people to drag it to their Bookmark bar, make a link like this:
    <a href="javascript:var spanArray=document.getElementsByTagName('span');va r number_spans=spanArray.length;for(var i=0;i<number_spans;i++){var target=spanArray[i];target.style.visibility='visible';};
    ">Show Spans</a>
    Simple as that.
    Last edited by lemon-tree; 04-28-2010 at 11:54 AM.

  9. #9
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Javascript change style attribute of span

    You need single quotes around 'visible'
    Last edited by descalzo; 04-28-2010 at 11:50 AM.

  10. #10
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Javascript change style attribute of span

    Yes, that is true. I have changed it now

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. javascript text class change for heading
    By jakeselectronics in forum Programming Help
    Replies: 2
    Last Post: 10-17-2009, 12:31 PM
  2. Can't Change Style
    By Against The Storm in forum Free Hosting
    Replies: 2
    Last Post: 04-21-2009, 07:00 PM
  3. help with float:left; attribute
    By dellerdynamics in forum Programming Help
    Replies: 3
    Last Post: 12-12-2008, 02:03 PM
  4. Javascript to change iframe url
    By thezone1 in forum Programming Help
    Replies: 3
    Last Post: 04-25-2008, 03:37 PM
  5. Is it possible to change the Corporate Banner style?
    By NetoBochas in forum Free Hosting
    Replies: 1
    Last Post: 09-27-2007, 05:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers