Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mustafa Khan
6,224 Pointsgetting all titles
If in my html I had some of my elements given a priority, so it would like like this: <p priority = 1> lorem ipsum dolor sit amet</p> how would i select all the elements that have a priority attribute, and also how to select all the elements of a specific priority?
1 Answer
Steven Parker
243,656 PointsYou can do this with an attribute selector.
For examples (using CSS):
p[priority] { /* any paragraph with a priority */
font-weight: bold;
}
p[priority='1'] { /* only those with priority 1 */
color: red;
}
The selector itself can be used in JavaScript functions like "querySelectorAll", or with jQuery.
See the MDN documentation page for more details.
And you might enjoy the CSS Selectors course.
Mustafa Khan
6,224 PointsMustafa Khan
6,224 PointsIf I wanted to select something that had a priority, but not necessarily a paragraph, then would a just remove the p, or the brackets as well?
Steven Parker
243,656 PointsSteven Parker
243,656 PointsIf you remove the "p" (and don't replace it with something else), it will select anything that has the attribute.