Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Creating custom tags/attributes .. just invalid of unacceptable?

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating custom tags/attributes .. just invalid of unacceptable?

    Hello all,
    I thought this was a HTML related post so I posted here, if I am wrong then I apologize.

    The title must have cleared the point. If not can anyone tell me that using custom tags in HTML using javascript is just invalid or unacceptable?? What I mean is, "Is using custom tags/attributes invalid for the w3c standards?" or it is completely illegal(sorry could not find an appropriate word). I am asking this because I have tried to use custom attributes in one of my scripts.

    Thanks everyone.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    From my limited knowledge, I believe it would be "wrong" but not change functionality.

    I believe that, due to updates to html, browsers are designed to ignore any tags/attributes they are now programmed to handle.

    For example:
    <iframe>this text is displayed if iframes are not enabled</iframes>

    The text isn't displayed on old browsers because they are programmed to, but rather because they aren't programmed not to. The iframe tags are ignored, and the text isn't, because the old browsers don't know not to. The new browsers are programmed to ignore it and replace with the iframe.

    Also, obviously attributes are ignored... <a djlkasdfjalsjfk="something" href...> won't cause an error. (But it won't validate.)

    However, I'd think this isn't great practice for some reasons, so might not be a good idea.

    The way to avoid this, if you need something like extra markups in the code is to use comments:

    <!--mytag-->.........<!--/mytag-->

    Javascript could interpret that just as easily, and it would cause no errors nor validity problems.

    Hope this helps.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, in one sense this does help but can you tell me how do I make that <!--mytag--><!--/mytag--> thing work?? And what about attributes?? Can I use them?? By the way if I use my own custom dtd or xml scheme then is it possible to use custom tags/attributes without violation of the HTML 4.0 spec and validate it successfully??

    Sorry for a lot of questions. But I am just a newbie.

    Thanks again!!!

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I really have no clue about the technical sides of things.

    As I said... basically.... anything the browser is not specifically programmed to deal with, is ignored. (I think.)

    You can't just make markups. Actually, I started a thread about this quite a while ago. Maybe there was some info in there, but the basic answer was no.
    If you want to make your own, then you could have some, and interpret them with php, javascript or something else, but you'd need something more than html (and it wouldn't be particularly easy).

    For the comments, that's just a comment. I just made it look like an html tag.
    <!--comment here and it's ignored by html....-->
    So... you can put whatever you want in there and it'll just be in the source-- not interpreted by the browser as a tag AND not displayed as text. That's what comments are for.

    Comments, I have seen, are used in text files to be used in php, for example:
    <!--new user data starts here-->
    and php will recognize that and do some different formatting with the contents seperated at that point.

    From the phrasing of your question, I assumed that you knew what you would do with it and just wanted to know if it was valid in html.
    I assume there is a way to use javascript, or whatever language you want, to do something with the tag, but it depends on what you want (at least how to do it depends on that).

    Not sure what you are asking about attributes. With the right coding, you could use <!--mytag attribute="..."--> and have that do something, assuming the javascript/php/etc could output the right result from that.

    If you are asking about just using custom attributes, you should note that, as I said, they are ignored if not supported.

    Created a custom doctype/dtd.... hmm....
    I don't think this alone would create functionality for a tag. I would think the tags are hard coded into the browsers, at least generally. The dtd might be able to, for example, tell the browser to ignore a tag, or specify a particular way to handle a tag, but I don't think it could actually add a tag (or attribute).


    Most of this is just guessing, based on what I've seen.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for you reply. I don't really think that browsers usually ignore tags/attributes which are not hard coded in them. For e.g try this in FF(only works in FF).

    Code:
    <html>
    <head>
    <script type="text/javascript">
    window.onload = function(){
    redlist = document.getElementsByTagName("RED");
    for(var i=0;i<redlist.length;i++){
    redlist[i].style.color = "red";
    }
    }
    </script>
    <body>
    <red>test</red>
    </body>
    </html>

  6. #6
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    arent you able to create your own doc-type though? and wouldnt that include programming your own tags/atributes?
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi
    If not can anyone tell me that using custom tags in HTML using javascript is just invalid or unacceptable??
    Using either custom elements or attributes will produce invalid markup. Using custom elements is pointless as they'll be ignored and may never make it into the document tree. The same is true more-or-less the same for attributes, though some browsers may add them to the document tree.

    I am asking this because I have tried to use custom attributes in one of my scripts.
    Why? If it's data for scripts, then why is it in the markup? You can quite easily associate information with an element by storing it an object and using the id attribute value (or name, for form controls) to identify that data.


    Quote Originally Posted by djr33
    I believe that, due to updates to html, browsers are designed to ignore any tags/attributes they are now programmed to handle.
    It is, as I understand it, for the sake of handling various proprietary extensions implemented by different browser vendors, particularly during the early Web when elements and attributes were implemented left, right, and centre with little (or no) consensus.

    The way to avoid this, if you need something like extra markups in the code is to use comments ...
    I wouldn't recommend that much, either. If something really is content, it can either be marked up with the proper element, or a generic (div or span). There should be no need at all to start inventing new things. If that thing isn't content, it shouldn't be in the markup at all.


    Quote Originally Posted by shachi
    By the way if I use my own custom dtd or xml scheme then is it possible to use custom tags/attributes without violation of the HTML 4.0 spec and validate it successfully??
    No. The HTML specification defines what HTML is. It cannot be extended or augmented. One can write a DTD that defines extra elements or attributes, write a document that uses them, and have it validated. However, that document is not HTML.

    More the point, why do you think this would actually be useful? No browser will understand these new items. They won't assign meaning, but simply ignore them as something alien and pointless.


    Quote Originally Posted by djr33
    The dtd might be able to, for example, tell the browser to ignore a tag, or specify a particular way to handle a tag, ...
    No, it cannot. The document type definition simply specifies the set of elements, their attributes and content models, and the entities that can be used in a document. The meaning of an element or attribute is defined in the prose of a relevant specification, and only there.


    Quote Originally Posted by shachi
    I don't really think that browsers usually ignore tags/attributes which are not hard coded in them.
    Yes, they do. Adding an element or attribute to the document tree doesn't mean that any significance was attached to it - that would simply be a blind action on the part of the tag-soup parser.

    All bets are off when one starts doing this sort of thing, which is precisely why one shouldn't.

    ... (only works in FF)
    Thank you for making my point.

    Mike

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There's the answer... Mike's answer is more complete and correct than mine.

    If you NEED to add a tag, use comments.
    If you can use a div/span instead, do that... just give it a class and use css to format.

    And, why?

    There might be another way around it...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Custom elements do not appear to work in IE. The example given also works in Opera though as does this:

    Code:
    <style type="text/css">
    red {
    color:red;
    }
    </style>
    HTML Code:
    <red>Hi</red>
    in both FF and Opera but, not in IE (IE thought it was javascript or active X by the way). The invented attributes and invalid to a particular element attributes thing is used in several DD scripts. Ajax Tabs comes to mind with its rev and rel attributes. Rev being invented, I think and rel, I believe invalid for the anchor tag with which it is used.

    Another way can always be found.

    As mwinter points out, the real problem is that these things cannot be relied upon cross browser, or even (I might add) in different situations, even if they do happen to work in some cases.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I don't need custom tags but attributes(because in the script I am developing(something like a rubber band selection script) there are a lots of identifiers for different objects and I can't use classes or ids the simple reason is that it needs to identify all the elements for different things like is it selected or not should it be dragged or not for more control) I hope I was able to clear my point.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •