Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Custom html element names

Reply
Thread Tools

Custom html element names

 
 
emf
Guest
Posts: n/a
 
      05-05-2013
It suddenly crossed my mind that it might be possible to create your own
html elements to replace <span>, and define them in CSS.

So I tried it in one of my first webpages:

https://files.nyu.edu/emf202/public/bd/warprayer.html

Since still I have a rather limited number of webpages, sometimes I feel
going back and revising and updating my old webpages' code. This one
needs more revising (it has mistakes in the image tags), but for now
what I did was create 2 new elements <prayer> and <angel> to replace
classes (<span class="prayer"> and <span class="angel">).

It works in FF but not in IE, so I'll be reverting to the <span> code
shortly. For a brief moment it seemed to me a pretty good idea
though!... But before re-revising the code, I'd like to hear more
experienced programmers' opinions on this. What do you think?

Thanks,

emf

--
Natal Transits Calculator
https://files.nyu.edu/emf202/public/...ltransits.html
 
Reply With Quote
 
 
 
 
richard
Guest
Posts: n/a
 
      05-05-2013
On Sat, 04 May 2013 20:59:42 -0400, emf wrote:

> It suddenly crossed my mind that it might be possible to create your own
> html elements to replace <span>, and define them in CSS.
>
> So I tried it in one of my first webpages:
>
> https://files.nyu.edu/emf202/public/bd/warprayer.html
>
> Since still I have a rather limited number of webpages, sometimes I feel
> going back and revising and updating my old webpages' code. This one
> needs more revising (it has mistakes in the image tags), but for now
> what I did was create 2 new elements <prayer> and <angel> to replace
> classes (<span class="prayer"> and <span class="angel">).
>
> It works in FF but not in IE, so I'll be reverting to the <span> code
> shortly. For a brief moment it seemed to me a pretty good idea
> though!... But before re-revising the code, I'd like to hear more
> experienced programmers' opinions on this. What do you think?
>
> Thanks,
>
> emf


That's one thing XML is for.
XML allows you to use your own tags.
 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      05-05-2013
2013-05-05 3:59, emf wrote:

> It suddenly crossed my mind that it might be possible to create your own
> html elements to replace <span>, and define them in CSS.


You cannot define elements in CSS. All you can do in CSS is to make
presentation suggestions on the rendering of elements. If that's what
you mean by "define them in CSS", yes, you can do that, with the usual
CSS caveats ( http://www.cs.tut.fi/~jkorpela/css-caveats.html ).

> It works in FF but not in IE,


It works in IE 9 and newer. In older versions, you custom tags are
effectively ignored so that they cannot be styled. There's a partial fix
to this: "introduce" your custom elements this way:

<script>
document.createElement('foo');
document.createElement('bar');
</script>

before any style sheet or reference to a style sheet (i.e., put the
<script> element at the start of the <head>).

> But before re-revising the code, I'd like to hear more
> experienced programmers' opinions on this. What do you think?


There's not much to be said about the programming side of the matter
(the JavaScript code above is trivial, though if you have many custom
tags, you can make it shorter by writing a loop).

On the authoring side, here's my summary (abridged from
http://www.cs.tut.fi/~jkorpela/pragmatic-html.html8 ):
- you can't add functionality to custom elements, except by JavaScript
- in non-CSS rendering, presentation is as if the tags were not there
- some day some browser might start recognizing "foo" as a defined
element, and then you're in trouble (you can minimize the risk by using
cryptic tag names, but what's the point then?)
- validators and checkers will report the tags as errors, and then you
have difficulties in working with the real errors.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      05-05-2013
On Sat, 04 May 2013 20:59:42 -0400, emf wrote:

> It suddenly crossed my mind that it might be possible to create your own
> html elements to replace <span>, and define them in CSS.
>
> So I tried it in one of my first webpages:


You're not quite doing what you think you're doing, and you're also
relying on how browsers handle and apply css to unrecognised elements,
which isn't guaranteed to be consistent across browsers or between
browser versions.

Generally, most browsers will ignore tags they don't recognise, including
attributes of those tags, but show the child nodes of those tags (whether
they're textnodes or elements).

Generally, browsers will apply css to nodes xml style.

However, it's never going to be a good idea to invent your own html tag
soup with any w3c dtd that relies on either of these behaviours.

There's nothing to stop you creating your own xml with your own dtds and
stylesheets. Browsers may even display this as you want ...

--
Denis McMahon, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
emf
Guest
Posts: n/a
 
      05-06-2013
On 2013-05-05 03:44 Jukka K. Korpela wrote:
> 2013-05-05 3:59, emf wrote:
>
>> It suddenly crossed my mind that it might be possible to create your own
>> html elements to replace <span>, and define them in CSS.

>
> You cannot define elements in CSS. All you can do in CSS is to make
> presentation suggestions on the rendering of elements. If that's what
> you mean by "define them in CSS", yes, you can do that, with the usual
> CSS caveats ( http://www.cs.tut.fi/~jkorpela/css-caveats.html ).
>
>> It works in FF but not in IE,

>
> It works in IE 9 and newer. In older versions, you custom tags are
> effectively ignored so that they cannot be styled. There's a partial fix
> to this: "introduce" your custom elements this way:
>
> <script>
> document.createElement('foo');
> document.createElement('bar');
> </script>
>
> before any style sheet or reference to a style sheet (i.e., put the
> <script> element at the start of the <head>).
>
>> But before re-revising the code, I'd like to hear more
>> experienced programmers' opinions on this. What do you think?

>
> There's not much to be said about the programming side of the matter
> (the JavaScript code above is trivial, though if you have many custom
> tags, you can make it shorter by writing a loop).
>
> On the authoring side, here's my summary (abridged from
> http://www.cs.tut.fi/~jkorpela/pragmatic-html.html8 ):
> - you can't add functionality to custom elements, except by JavaScript
> - in non-CSS rendering, presentation is as if the tags were not there
> - some day some browser might start recognizing "foo" as a defined
> element, and then you're in trouble (you can minimize the risk by using
> cryptic tag names, but what's the point then?)
> - validators and checkers will report the tags as errors, and then you
> have difficulties in working with the real errors.


OK, it was just an idea. The

> document.createElement('foo');


seems an interesting possible idea for the future.

The webpage was corrected and now validates for HTML5. But I couldn't
fin a "Valid HTML5" icon; I used the HTML 4.01 for now. Why don't they
have one?

emf

--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/...intmebabe.html
 
Reply With Quote
 
Denis McMahon
Guest
Posts: n/a
 
      05-06-2013
On Mon, 06 May 2013 04:46:49 -0400, emf wrote:

> The webpage was corrected and now validates for HTML5. But I couldn't
> fin a "Valid HTML5" icon; I used the HTML 4.01 for now. Why don't they
> have one?


There is no HTML 5 standard yet. What you've validated against is a
proposed standard. The final standard may be different in a way that
makes your page invalid.

--
Denis McMahon, (E-Mail Removed)
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      05-06-2013
2013-05-06 11:46, emf wrote:

> The webpage was corrected and now validates for HTML5. But I couldn't
> fin a "Valid HTML5" icon; I used the HTML 4.01 for now. Why don't they
> have one?


Maybe they read my rant against such icons and admitted that I am right:
http://www.cs.tut.fi/~jkorpela/html/...tion.html#icon

Seriously, I think they just realized that using such icon would be
disproportionately absurd in the case of *experimental* validation
against a *draft* (an unspecified draft at that). Both the validator
itself and the draft(s) used may and will change without prior notice
(and without posterior notice), so what would be the point of using an
icon just because your page happened to "validate" at one specific
moment of time?

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
Tim Streater
Guest
Posts: n/a
 
      05-06-2013
In article <km7snq$jq2$(E-Mail Removed)>,
Denis McMahon <(E-Mail Removed)> wrote:

> On Mon, 06 May 2013 04:46:49 -0400, emf wrote:
>
> > The webpage was corrected and now validates for HTML5. But I couldn't
> > fin a "Valid HTML5" icon; I used the HTML 4.01 for now. Why don't they
> > have one?

>
> There is no HTML 5 standard yet. What you've validated against is a
> proposed standard. The final standard may be different in a way that
> makes your page invalid.


In other words, such icons are a stupid waste of time.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      05-06-2013
2013-05-06 12:22, Denis McMahon wrote:

> There is no HTML 5 standard yet. What you've validated against is a
> proposed standard.


No, W3C HTML5 is still at the "Candidate Recommendation" stage; next
year, it is expected to become "Proposed Recommendation" and then
"Recommendation". It will most probably never become a standard in any
other meaning than W3C Recommendation.

The W3C working group has already decided to make changes to HTML5, so
HTML5 CR does not reflect even working group consensus.

Besides, it has not been disclosed what the validator is really
validating against. It could be WHATWG Living HTML, or W3C HTML 5.1
Nightly, or even something somewhat different.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
 
Reply With Quote
 
emf
Guest
Posts: n/a
 
      05-07-2013
On 2013-05-06 05:29 Jukka K. Korpela wrote:
> 2013-05-06 11:46, emf wrote:
>
>> The webpage was corrected and now validates for HTML5. But I couldn't
>> fin a "Valid HTML5" icon; I used the HTML 4.01 for now. Why don't they
>> have one?

>
> Maybe they read my rant against such icons and admitted that I am right:
> http://www.cs.tut.fi/~jkorpela/html/...tion.html#icon
>
> Seriously, I think they just realized that using such icon would be
> disproportionately absurd in the case of *experimental* validation
> against a *draft* (an unspecified draft at that). Both the validator
> itself and the draft(s) used may and will change without prior notice
> (and without posterior notice), so what would be the point of using an
> icon just because your page happened to "validate" at one specific
> moment of time?


Well, in this case at the very least those icons provide an easy way and
a reminder for the author, that is me, to recheck the page whenever in
the future I will think about it.

emf

--
Date Calculator with all-purpose JS code
https://files.nyu.edu/emf202/public/...alculator.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
Conversion from a HTML element to table element vinayak Javascript 5 01-18-2008 10:08 AM
Generating new element names from old element names UpgradeMyBrain@gmail.com XML 2 10-20-2006 08:24 AM
Possible to traverse the children of an element without specifying child element names? Matt XML 2 10-12-2004 08:23 AM
Matching attribute names to element names in a different path Carl XML 0 04-01-2004 01:15 PM



Advertisments