Fair enough. However, how do you retrieve data from a let's say div? I even used it's ID to hide a data in it: <div id="mydiv_1">click here to alert 1</div> <div id="mydiv_2">click here to alert 2</div> Code (markup): //I'm spoiled by jquery so forgive me I forgot the right syntax in javascript: $('div').click(function () { var id = $(this).attr('id').slice(6); alert(id); }); Code (markup):
What data is there that isn't there as text or the ID? Not sure I even follow your question. Of course, I find jQuery's "slice" method complete gibberish and still don't understand it's practical application -- so that code really isn't helping me any to understand what you mean -- or even what that needlessly cryptic code is supposed to do. Oh wait, I get it... Heh... I'd put the data in a span (and if mulitple spans use a class) and extract it from there -- though really that's NOT a usage scenario I'd even have on a website in the first place... if you have the data already showing in the content like a good dooby, what the devil do you need to alert for or perform any other scripting act upon the element for?!? Starts to sound like "scripting for nothing". Though in the HANDFUL of cases where I need to pass something from markup to scripting, I use classes since that usually lines up with needing some form of styling anyways. An example would be a form validation where I might have class="v_email" for valiating an e-mail, "v_numeric v_min_32 v_max_64" for a number that must be a number and in the range of 32..64. But I wouldn't call any of that "data".
It was just an example of a list/detail. Imagine displaying div with details for item id 1, item id 2 instead of alert. So I wouldn't have all the data in a content in the first place, I would just store referencing ID and I would load the details data trough Ajax. So I need to store that ID somewhere: is it within a element ID ("mydiv_1") where 1 is the referencing ID that I need; is it in a rel attribute (OK, you suggested it's a bad idea); is it in a data-id attribute that HTML5 offers... Maybe in a class! Where?
The JavaScript counterpart is here: var div = document.getElementsByTagName('div'); for (var i = 0; i < div.length; i++) { (function(x){ div[x].addEventListener('click', function() { var array = Array.prototype.slice.call(div[x].id); console.log(array[6]); }); })(i); } Code (markup): So, what are you trying to do. I do not understand. If I want to hide my data, I would put it in arraybuffer, so people want to see it might need some times to decode.
We need to go back to the topic, "Is data-* really useful in HTML5 or we can do it other way" Let's say you have: <a href="/?id=1">go to detail page 1</a> <a href="/?id=2">go to detail page 2</a> Code (markup): Now the id is referencing ID that I need to read when opening detail page. Now imagine you have to have this situation in other HTML element, DIV for example. Where do you put that referencing id? HTML5 users would suggest: <div data-id="1"> Code (markup): What other options do we have? I suggested <div rel="1"> Code (markup): but deathshadow pointed out, that's not what rel is for. I agree. That's why I usually include that ID in the ID of the element: <div id="mydiv_1"> Code (markup): Now I can extract that referencing ID, from the 6th position of the element id value. What are other options? Class maybe? <div class="1"> Code (markup): and then get the class name of that element to get the referencing ID. Maybe this solution: <div> <span class="this-element-will-not-be-displayed-it-is-for-storing-data-only">1</span> </div> Code (markup): and then fetch the content of that span? I'm just asking what are the other options for data-id, and data-* in general.
I think you missed what I meant by a span and what I meant by 'data'. <div>click here to alert <span>1</span></div> Since that's the DATA. If it's actually content, you should be showing it as content and manipulating... well, the CONTENT. If it's not content it has no business in the markup. I don't see any other real usage scenario for it. If it's data / content, why in the devil isn't it in the markup AS CDATA?!? Plaintext -- you know... CONTENT But again, that's the whole "unwritten rule of JavaScript" thing I had drilled into my head a decade or so ago talking. I just don't see a real world scenario where anyone who actually knows what they are doing would be using those; they do nothing but encourage sloppy coding and bloating out the page with crap no visitor to a website would actually give a flying purple fish about. Basically, the same problem I have with TITLE and the whole micro-data bullshit. If you need to use them, there's probably something wrong with the content of the tag you're applying them to; part of why I say you should write content FIRST, markup SECOND; that way you're not dicking around later adding crap that to be brutally frank is NOT "writing for the user" -- what we've been told to do since 1998 that now HTML 5 wants to throw out the window along with every other good practice and improvement in site-building methodology of the past decade and a half.
Yeah, flash's almost dead. The Internet changes so fast, that in couple years almost nobody's gonna use it.
HTML5 will never catch up to flash, IMO. Flash is still vastly better than HTML5 for videos and games, and Adobe has already converted flash into a robust mobile app creation system, that far exceeds both the default systems and the HTML5-conversion systems. Flash isn't dying, it's evolving.
Thanks man, but it was more like question than suggestion. Anyway, glad it helped. Apartman Karlobag Kvarner