Jump to content
Sign in to follow this  
uw3c

All HTML elements can have attributes?

Recommended Posts

Hello everyone
In the first bullet point of the chapter summary on HTML attributes (bottom of the page) it is stated: "All HTML elements can have attributes".

Am I misunderstanding that by thinking empty elements can also have attributes? I tried to verify this by writing:

 

(XHTML)

<br title="test"/>
or
<br title="test"></br>

or

 

(standard HTML)

<br title="test">

only to watch it not work as per my expectation because no tooltip is shown, however I hover over the document (code author: Mrw3c).

Last I checked on the section about HTML elements, it does not say if an attribute is considered content or not. It only says the text between the start tag and the end tag is content and as far as I know, attributes are meta information, meaning they are not content. Of course, w3schools states an attribute 'provides extra information' so I could deduct that indeed means meta information.
Aside from that, I checked the w3schools documentation on the <br> tag: and it says "The <br> tag is an empty tag which means that it has no end tag".
Nonetheless, it does say that the <br> tag supports global attributes such as the 'title' attribute. However, as you can see above, I tried that but unfortunately it did not work for me.
Am I missing something in my understanding?
Thanks
Edited by Mrw3c

Share this post


Link to post
Share on other sites

Why would you expect a line break to show a tool tip? I don't think you would be able to hover over a br element at all, I don't think it has a size greater than 0. I suppose you could try to style the br to make it visible, but it's not designed to be a visible element in the first place. There's nothing to hover over to see a tool tip.I don't think that a title attribute is a great test for a non-visible element. You could give the br element an ID, and then access the element through Javascript. Or you could give it a class or style attribute and then use CSS with it (but, again, I don't know if that would have much of an effect on a non-visible element).For other reference, check the MDN documentation on global attributes:https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes

Share this post


Link to post
Share on other sites

Attributes don't go between tags, they go inside tags. Empty elements have still one tag inside which you can put attributes.

 

Attributes are not content. Content is what goes between the tags.

Share this post


Link to post
Share on other sites

Attributes don't go between tags, they go inside tags. Empty elements have still one tag inside which you can put attributes.

 

Attributes are not content. Content is what goes between the tags.

 

I am not sure if you read my post but I corrected that already:

 

 

 

It only says the text between the start tag and the end tag is content and as far as I know, attributes are meta information, meaning they are not content. Of course, w3schools states an attribute 'provides extra information' so I could deduct that indeed means meta information.

 

meaning I understand attributes are meta information and not content. Seeing I have this insight, I don't understand why you replied about that.

Share this post


Link to post
Share on other sites

br is a terrible choice for this experiment. How large is a br ? Did you try applying a border to the br so you could identify it ?

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>title</title><style>.iamred {border:1px solid red;}</style></head><body><h3>The br follows...</h3><br class="iamred" title="title"/><h3>The br is above</h3><span  class="iamred" title="Free Web tutorials">W3Schools.com</span></body></html>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×