I'm new to CSS, and after learning about ID selectors, the only difference between them and class selectors is the fact you can only have one specific id per element, whereas multiple elements can share the same class name. But then it's easy: name an element a class name that you won't use for any other element. So it seems in that sense, a class can be treated as an I.D.  I'm new to CSS, so I may be missing something here. What advantage do I get using an ID selector over a class selector in a particular case?  Thanks.
29285
What's the difference between &lt;div class=""&gt; and &lt;div id=""&gt; when it comes to CSS? Is it alright to use &lt;div id=""&gt;?  I see different developers doing this in both ways, and since I'm self taught, I've never really figured it out.
12151
What characters/symbols are allowed within the CSS class selectors? I know that the following characters are invalid, but what characters are valid?  ~ ! @ $ % ^ &amp; * ( ) + = , . / ' ; : " ? &gt; &lt; [ ] \ { } | ` #
111353
HTML (or maybe just XHTML?) is relatively strict when it comes to non-standard attributes on tags. If they aren't part of the spec, then your code is considered non-compliant.  Non-standard attributes can be fairly useful for passing along meta-data to Javascript however. For instance, if a link is suppose to show a popup, you can set the name of the popup in an attribute:  &lt;a href="#null" class="popup" title="See the Popup!"     popup_title="Title for My Popup"&gt;click me&lt;/a&gt;   Alternatively, you can store the title for the popup in a hidden element, like a span:  &lt;style&gt;     .popup .title { display: none; } &lt;/style&gt; &lt;a href="#null" title="See the Popup!" class="popup"&gt;     click me     &lt;span class="title"&gt;Title for My Popup&lt;/span&gt; &lt;/a&gt;   I am torn however as to which should be a preferred method. The first method is more concise and, I'm guessing, doesn't screw with search engines and screen readers as much. Conversely, the second option makes storing large amounts of data easier and is thus, more versatile. It is also standards compliant.  I am curious what this communities thoughts are. How do you handle a situation like this? Does the simplicity of the first method outweigh the potential downsides (if there are any)?
104769
I'm not sure why I need to use ul-li vs simply using divs when listing items. I can make both look exactly the same so where is the functional advantage to creating an unordered list vs lining up divs?
72086
I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going on.  var d = document; var odv = d.createElement("div"); odv.style.display = "none"; this.OuterDiv = odv;  var t = d.createElement("table"); t.cellSpacing = 0; t.className = "text"; odv.appendChild(t);   I would like to know if there is a better way to do this using jQuery. I've been experimenting with:  var odv = $.create("div"); $.append(odv); // And many more   But I'm not sure if this is any better.
103335
I know that embedding CSS styles directly into the HTML tags they affect defeats much of the purpose of CSS, but sometimes it's useful for debugging purposes, as in:  &lt;p style="font-size: 24px"&gt;asdf&lt;/p&gt;   What's the syntax for embedding a rule like:  a:hover {text-decoration: underline;}   into the style attribute of an A tag? It's obviously not this...  &lt;a href="foo" style="text-decoration: underline"&gt;bar&lt;/a&gt;   ...since that would apply all the time, as opposed to just during hover.
115241
I'm trying to add a custom CSS class to the &lt;body&gt; tag, How can I modify or pre-process the &lt;body&gt; tag to add the class body, Is it right to style the &lt;body&gt; tag with css file?
67655
Does anyone know how to select an item in the DOM by ID with jQuery, when that ID has a space?   For example, the ID of my item would be  &lt;div id="content Module"&gt;Stuff&lt;/div&gt;   How would I select this with jQuery?   If I just do   $("#content Module").whatever()    jQuery will try to find an item with both the ID of content and the ID of Module, which is not what I am looking for.  I should add that I am working with an old code base where these two word ids are used extensively, so going through and changing all the IDs would be bad.
40326
According to  the following metadata is exposed for badges:  Id UserId Name Date   Why isn't class exposed in some way? It's obviously in the schema, since we can sort / filter in the UI. Come to think of it the description might be something useful to filter on in a query as well, e.g.:     Give me the name and count for all gold badges that contain the word 'vote' in the description.   I am not sure if class is exposed in a different way for tag-related badges (I suspect the schema is more complex, since their existence relies on them having been awarded in that class at least once).  (Also, the Id in the Badges table is not the badge id, it seems to be an IDENTITY / auto-increment column.)
17190
Is there a way to edit SVG files in Illustrator where you can specify a CSS class for each path?  I already know in Illustrator that if you give the layer name an actual name, Illustrator will use that name as the path's ID, which is fine if you don't plan on reusing the icon more than once on the same page.  My current workaround is to just use the IDs method, but then later convert the IDs to classes in my code editor, but it's pretty annoying to have to do every time I generate my SVG sprite.  If that's currently not possible in Illustrator, are there any other apps that will allow you to specify that? Or maybe a Grunt or Gulp package?  It looks like you might be able to do it with Inkscape with a , so I might look at that if there's no other good solutions out there.
3057
I need to change an element's ID using jQuery.    Apparently these don't work:  jQuery(this).prev("li").attr("id")="newid" jQuery(this).prev("li")="newid"   I found out that I can make it happen with the following code:  jQuery(this).prev("li")show(function() {     this.id="newid"; });   But that doesn't seem right to me. There must be a better way, no? Also, in case there isn't, what other method can I use instead of show/hide or other effects? Obviously I don't want to show/hide or affect the element every time, just to change its ID.  (Yep, I'm a jQuery newbie.)  Edit I can't use classes in this case, I must use IDs.
28047
Is there any syntactical way in jQuery to define multiple CSS attributes without stringing everything out to the right like this:  $("#message").css("width", "550px").css("height", "300px").css("font-size", "8pt");   If you have, say, 20 of these your code will become hard to read, any solutions?  From jQuery API, for example, jQuery understands and returns the correct value for both   .css({ "background-color": "#ffe", "border-left": "5px solid #ccc" })    and   .css({backgroundColor: "#ffe", borderLeft: "5px solid #ccc" }).   Notice that with the DOM notation, quotation marks around the property names are optional, but with CSS notation they're required due to the hyphen in the name.
85136
All right, say I have this:  &lt;select id='list'&gt;     &lt;option value='1'&gt;Option A&lt;/option&gt;     &lt;option value='2'&gt;Option B&lt;/option&gt;     &lt;option value='3'&gt;Option C&lt;/option&gt; &lt;/select&gt;   What would the selector look like if I wanted to get "Option B" when I have the value '2'?  Please note that this is not asking how to get the selected text value, but just any one of them, whether selected or not, depending on the value attribute. I tried:  $("#list[value='2']").text();   But it is not working.
110764
In the past and with most my current projects I tend to use a for loop like this:  var elements = document.getElementsByTagName('div'); for (var i=0; i&lt;elements.length; i++) {     doSomething(elements[i]); }   I've heard that using a "reverse while" loop is quicker but I have no real way to confirm this:  var elements = document.getElementsByTagName('div'),      length = elements.length;  while(length--) {     doSomething(elements[length]); }   What is considered as best practice when it comes to looping though elements in JavaScript, or any array for that matter?
22840
I'm building an HTML UI with some text elements, such as tab names, which look bad when selected. Unfortunately, it's very easy for a user to double-click a tab name, which selects it by default in many browsers.  I might be able to solve this with a JavaScript trick (I'd like to see those answers, too) -- but I'm really hoping there's something in CSS/HTML directly that works across all browsers.
100110
I've been teaching myself Objective-C over the past month or so (I'm a Java head) and I've got my brain wrapped around most of it now. One thing that's confusing me at the moment: What's the difference between importing a class via @class vs doing a #import?   Is one better than another one, or do I need to use one instead of the other in certain cases? I've been using just #import so far.
51398
I remember seeing somewhere that IDs are composed of a few pieces. I always have a hard time trying to find that information when I'm looking for it. What I mean by the above is that the various places in the ID represent different things - for example the first few characters represent what type of sObject it is.