Jump to content

HTML Attribute


The Little Guy

Recommended Posts

is there an attribute where I can place text in there so when I run javascript I can look at that text so the javascript knows what to do with it?

 

for example I am making a filter system, and when a user clicks on "live" I want to hide everything that isn't live. If he/she clicks on "private" I want to show everything that is "private".

 

so for example....

 

<a href="javascript:void(0);" onclick="showHide('live');">Show Live Items</a> |
<a href="javascript:void(0);" onclick="showHide('private');">Show Private Items</a>

<div item="live"><img src="/some/image.jpg" /></div>
<div item="live"><img src="/some/image.jpg" /></div>
<div item="private"><img src="/some/image.jpg" /></div>
<div item="private"><img src="/some/image.jpg" /></div>
<div item="live"><img src="/some/image.jpg" /></div>
<div item="private"><img src="/some/image.jpg" /></div>

 

then in the javascript I could do something like this:

 

function showHide(status){
     var divs = document.getElementsByTagName('div');
     for(var i=0;i<divs.length;i++){
          if(divs[i].getAttribute('item') == status){
               divs[i].style.display = 'block';
          }else{
               divs[i].style.display = 'none';
          }
     }
}

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.