473,569 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about using <label>

Dormilich
8,658 Recognized Expert Moderator Expert
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 2053
drhowarddrfine
7,435 Recognized Expert Expert
Nothing wrong with doing stuff like that if it works.
Jan 5 '10 #2
Dormilich
8,658 Recognized Expert Moderator Expert
good ole HTML forgives nearly everything …
Jan 5 '10 #3
aktar
105 New Member
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
30020
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 id="uid">UserID: </label> <input name="UserID" type="text" value="" size="20"> <script language="Javascript1.2" type="text/javascript1.2">
3
13132
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 this, with a flush left margin:
5
8298
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 than having to click on the (possibly small) box or button. I recently tried to assign a label to a select "drop down list", but found that when...
5
1412
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
3802
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" onclick="__doPostBack('SitesRadioButtonList_3','')" language="javascript" />
1
1880
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> </body> ===
0
1600
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" ReadOnly="True" EnableViewState="False"></asp:textbox> <label class="col3">Rm Phone</label> <asp:textbox id="txtRmPhone" runat="server" cssclass="col4"...
7
1813
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
2563
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
7628
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8145
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7694
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5245
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3679
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1236
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.