- 2

Select all<a> links in which inside of the para tags

ans

7th Feb 2017, 2:13 AM
prabhu
prabhu - avatar
6 Antworten
+ 3
Without JQuery: var p=document.getElementById('myP'); // or anyelse ref' to an html element... var links=p.querySelectorAll('a'); // return an array of links elements inside 'p' element. or: var links=document.querySelectorAll('#myP a'); And with JQuery, you can do at least the same and solution of @florin holban... which may be corrected a few: var links=$('p a'); /* OR $('p > a') */ As in querySelectorAll(), the string argument required is a valid css selector, so difference between setting the greater than sign ( > ) or not is to select only direct childs or all childs and grand childs respectively ^^
7th Feb 2017, 5:05 PM
visph
visph - avatar
+ 2
@florin holban: What require correction in your answer is the parenthesis content: you write "$('p' 'a') or $('p' > 'a')" instead of "$('p a') or $('p > a')" ( too much quotes ;) )
7th Feb 2017, 11:01 PM
visph
visph - avatar
0
Maake a class.a-in-p and $('a-in-p') selects them. Or $('p' 'a') or $("p" > "a") for first class a tags of p tags
7th Feb 2017, 5:59 AM
florin holban
florin holban - avatar
0
True! My answer could be corrected! One does need to put this in a var and assign a query selector!
7th Feb 2017, 10:50 PM
florin holban
florin holban - avatar
0
:) true! :) i'm seeing it now! :)
7th Feb 2017, 11:04 PM
florin holban
florin holban - avatar
- 1
$ ("p a")
24th Mar 2018, 9:31 AM
Mahnoor Shahzad
Mahnoor Shahzad - avatar