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
https://forums.phpfreaks.com/topic/217519-html-attribute/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.