This may be a dumb question, but what is the CSS Selector for the attribute of <a>
that is "name"?
document.body.innerHTML = myString.anchor("HTML_String")
This JavaScript creates a <a>
element with the name "HTML_String."
How do I access only this element in my CSS?
This may be a dumb question, but what is the CSS Selector for the attribute of <a>
that is "name"?
document.body.innerHTML = myString.anchor("HTML_String")
This JavaScript creates a <a>
element with the name "HTML_String."
How do I access only this element in my CSS?
4 Answers
Reset to default 7CSS doesn't have a specific selector syntax for name attributes. You have to use the generic attribute selector syntax.
[att=val]
Represents an element with the att attribute whose value is exactly "val".
There is the [name="name"]
selector but it's not really cross-browser. Old versions of Internet Explorer don't support the selector by HTML attribute (that browser tho.........).
My suggestion is to always use class
es for CSS (even for unique elements) and id
s for JavaScript, while you'll leave the name
s for backend programming.
Add a class to the element and then a.myclass
use the [attribute=value] css selector, you can access it by using :
a[name=HTML_STRING] {
//your css
}
[name="yourName"]
or if it only should have any name:
[name]
an example for an input:
input.myClass[name="greatName"] {
...
}
But if your question is how to look for something within your "innerHTML": This isn't possible.
name
attribute for anchors has been removed from HTML as of HTML 5. Put an ID on the element you want to link to instead. – Quentin Commented May 15, 2016 at 18:55