Jump to content

help w/ javascript


dezkit

Recommended Posts

how do i make more than one?

 

<script type="text/javascript">
function change(ele) {
element = document.getElementById(ele);
(element.style.display == "block") ? element.style.display = "none" : element.style.display = "block";
}</script>

<div onclick="change('below')">
This is some text. Click here to show more text.
</div>

<div id="below" style="display:none; ">
This is some more text. You cannot see it on page load, click the text above to display it.
</div>

Link to comment
Share on other sites

Another one like this?

 

<script type="text/javascript">
function change(ele) {
element = document.getElementById(ele);
(element.style.display == "block") ? element.style.display = "none" : element.style.display = "block";
}</script>

<div onclick="change('below')">
This is some text. Click here to show more text.
</div>

<div id="below" style="display:none; ">
This is some more text. You cannot see it on page load, click the text above to display it.
</div>


<div onclick="change('another_one')">
This is some text. Click here to show more text.
</div>

<div id="another_one" style="display:none; ">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In commodo velit in nibh. Integer ultrices, diam vel feugiat porta, tellus libero accumsan elit, ac volutpat neque enim ut mi. Donec vel sapien. Nam interdum viverra mi. Cras purus felis, euismod eget, bibendum sed, auctor at, sapien. Duis non nibh. Suspendisse purus nulla, ultrices sit amet, fermentum iaculis, placerat rhoncus, augue. Integer nonummy ligula eget arcu. Pellentesque mauris. Curabitur accumsan magna quis eros.
</div>

Link to comment
Share on other sites

Not really sure what you are going for but here are a few ideas...

 

 

<script type="text/javascript">

 

var allDivs = array('id1', 'id2', 'id3');

 

// toggle only one at a time

function showOnlyMe(ele) {

  for(var i = 0; i < allDivs.length; i++) {

    if (allDivs != ele && document.getElementById(allDivs).style.display != 'none') {

      document.getElementById(allDivs).style.display = 'none';

    }

    else {

      document.getElementById(allDivs).style.display = 'block';

    }

  }

}

 

// toggle all up to and including one

function showUpToMe(ele) {

  // Until ele is found all divs will be displayed

  $setTo = 'block';

  for(var i = 0; i < allDivs.length; i++) {

    document.getElementById(allDivs).style.display = $setTo;

    if (allDivs == ele) {

      // Once ele is found the rest will not be displayed

      $setTo = 'none';

    }

  }

}

</script>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.