473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

about using <label>

Dormilich
8,658 Expert Mod 8TB
Hi,

I just have one thing about the label element, where I’m not certain. <label> is commonly used to attach visual/text information to a form control. so far, so good.
Expand|Select|Wrap|Line Numbers
  1. <!-- just to make it visible -->
  2. <input type="checkbox" value="yes" id="mysql">
  3. <label for="mysql">save MySQL</label>
Now supposing I want to toggle the visibility of a <div> containing e.g. a description of something via JavaScript. although it is not exactly specified this way, button (and their labels) should be only written inside a <form> (that’s why they are form controls). on the other hand side, labels with their IDREF attribute for would make excellent "show content" elements … (even better than anchors, in the semantic sense)
Expand|Select|Wrap|Line Numbers
  1. <label for="desc1" class="trigger">show content</label>
  2. <div id="desc1" class="hide">bla bla blubb …</div>
  3. /* CSS */
  4. .hide {
  5.     display: none;
  6. }
  7. // JavaScript
  8. function toggle()
  9. {
  10.     // for the general idea …
  11.     var vis = document.getElementById(this.for).style.display;
  12.     if ("none" == vis) {
  13.         vis = "block";
  14.         this.textContent = "hide content";
  15.     } else {
  16.         vis = "none";
  17.         this.textContent = "show content";
  18.     }
  19. }
  20. // after some prototyping …
  21. document.getElementsByClassName("trigger").addEventForEach("click", toggle, false);
what do you think about this (mis)use?
Jan 4 '10 #1
3 2023
drhowarddrfine
7,435 Expert 4TB
Nothing wrong with doing stuff like that if it works.
Jan 5 '10 #2
Dormilich
8,658 Expert Mod 8TB
good ole HTML forgives nearly everything …
Jan 5 '10 #3
aktar
105 100+
I've used custom attributes in some pages, thanks to HTMLs forgiving nature and they've proven invaluable in many places.
If you use jQuery for example, the HTML elements can be fetched by custom attributes, making the code very clean and flexible :)
Jan 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Xerxes | last post by:
Hi, can you tell me how I can make a <label> hidden? I have hidden the field after the label: var M_Hide = isNS4?'hide':'hidden'; var M_Show = isNS4?'show':'visible'; ..... <label...
3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
5
by: Brian Foley | last post by:
Hello, I am used to using the label tag with check boxes and radio buttons in html forms. This allows me to click on the text of the label to activate/deactivate the check box / button, rather...
5
by: Johnb41 | last post by:
I want an "order number" to be displayed more than once on my page. <script language="vb" runat="server"> ... dim ordernumber as string = "123456" page.databind() ... </script>
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
1
by: Hongbo | last post by:
Hi, I have a mobile form: === <body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm"> <mobile:Form id=Form1 runat="server"> <mobile:label runat="server" id="lblT" /> </mobile:Form>...
0
by: CharlesA | last post by:
Hi folks, I'm using ASP.net 1.1 with C# I've got this kind of thing going <div class="row"> <label class="col1">Rm Name</label> <asp:textbox id="txtRM" runat="server" cssclass="col2"...
7
by: Smokey Grindle | last post by:
How can you correctly use the <labelelement in asp.net? does the label custom control corelate to this tag correctly in the same way in that if you click it it will select the tied element? thanks
3
by: Homer J. Simpson | last post by:
I have the following stored procedure: ALTER PROCEDURE . AS BEGIN SET NOCOUNT ON; SELECT COUNT(*) FROM QUICKNOTES END ....and the following data source in my .aspx file:
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.