The Little Guy Posted November 2, 2010 Share Posted November 2, 2010 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'; } } } Quote Link to comment https://forums.phpfreaks.com/topic/217519-html-attribute/ Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 Most people use the class attribute for this reason, it sux, but until html5 there really isn't anything specifically for what your after that validates. Quote Link to comment https://forums.phpfreaks.com/topic/217519-html-attribute/#findComment-1129275 Share on other sites More sharing options...
The Little Guy Posted November 2, 2010 Author Share Posted November 2, 2010 does it work for more than 2 values in the class, for example.... class="classStyle live" class="classStyle private" Quote Link to comment https://forums.phpfreaks.com/topic/217519-html-attribute/#findComment-1129284 Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 Of course. You might need to search for the class your looking for though. Quote Link to comment https://forums.phpfreaks.com/topic/217519-html-attribute/#findComment-1129293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.