"I'm using SVG.js select()
function which uses querySelector()
function."
But your comment under TJ's answer suggests it uses querySelectorAll()
. There's a difference.
"What I'd like to do is to select the first inner element inside this element."
If it does use querySelector
, then use this selector:
"[id='1'] > *"
That'll give you the first child element inside the [id='1']
element.
But if it actually uses querySelectorAll
, then using TJ's :first-child
selector will work, but as he noted, you need to be aware that it will return all elements that are the first child of their parent.
You can use the >
child selector to ensure just one.
"[id='1'] > :first-child"
"Alternatively, I could select it by tag name. How to do it?"
I don't know which element you're referring to, but in general, include the tag name if the selector is selecting on attribute or position. That'll greatly help the engine to narrow down the set of elements.
// querySelector // querySelectorAll
"div[id='1'] > p" ... "div[id='1'] > :first-child"
"I tried select("[id='1']:first")
but received an error."
As TJ noted, that's an invalid selector. jQuery's selector engine is non-conforming to the standards in several different ways. Keep your selectors pure as much as possible so that you don't get hooked on needless dependencies.
"By the way, the reason I select it like that is that apparently querySelector
has a problem with id's which are numbers."
You can select by numbers if you escape the leading number.
"#\\1 > *"