Kevin Lindmark
Kevin Lindmark

Reputation: 1257

How do I select a custom element in jQuery?

I have a custom tag as seen below, but can't seem to select it with selector $("ix:nonNumeric"). $("[contextRef]") works fine, however. What is the correct selector?

<ix:nonNumeric contextRef="PERIOD0" name="se-gen-base:VasentligaHandelserRakenskapsaret" >000</ix:nonNumeric>

Upvotes: 0

Views: 1045

Answers (1)

j08691
j08691

Reputation: 207923

You need to escape the colon in your custom tag:

$("ix\\:nonNumeric").text()

Example:

console.log( $("ix\\:nonNumeric").text() )
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ix:nonNumeric contextRef="PERIOD0" name="se-gen-base:VasentligaHandelserRakenskapsaret" >000</ix:nonNumeric>

As the docs for selectors states:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\

Upvotes: 1

Related Questions