Welcome to the Treehouse Community
Looking to learn something new?
Marcus Schumacher16,616 Points
Need help with this J Query challenge
Using jQuery only, add to all links with the class "external", the target attribute with the value of "_blank".
I have no idea what to do here. Please help. Thanks.
Tushar SinghCourses Plus Student 8,692 Points
Whenever you have to change the attribute or set the attribute, use "attr".
"target"---- attribute to target "_blank"--- set the value of that attribute
It is asking you to target all anchor elements ("a") with the class "external," like so:
Brad Sprague5,523 Points
The phrasing of the question is confusing. to me I poked around long enough to guess the answer. In case it is a murky to someone else, here is what it is asking:
"add to all links": This means work with <a> elements.
'with the class "external" ': That gets us to a.external.
"Using jquery only," we find all such elements like this: $("a.external")
"The target attribute." As in the video, we can add/access the attributes like this: $("a.external").attr(). Now the name of the attribute is passed-in as a string, so we need this code: $("a.external").attr('target', )
Finally, "the value of "_blank". The English grammar is ambiguous. It either means "the literal value (which is) '_blank' " (meaning use a string literal). Or the author might have meant the value stored in the variable whose name is "_blank". I don't know how to make the determination except to try both and see which passes inspection. It turns out enclosing "_blank" in quotation marks passes, so it is a string literal, not a variable.