My question involves a div containing a question mark and some SVG elements. Here is the initial setup:
<div id="mydiv">?</div>
When validating a form submission in my code, I check if the div text contains a question mark like this:
const fieldText = $('#mydiv').text();
return fieldText.indexOf('?') !== -1;
Now, the content of the div includes an SVG question mark instead of just a plain text one:
<div id="mydiv">
<svg version='1.1' id='Layer_1' class='q-mark-svg' xmlns='http://www.w3.org/2000/svg' ... >
<!-- SVG path data here -->
</svg>
</div>
I need to modify my JavaScript validation to now check for the presence of an SVG element within the div rather than just a question mark. How can I achieve this?
I attempted the following approach by searching for 'svg' in the div text, but it did not work as expected:
const fieldText = $('#mydiv').text();
return fieldText.indexOf('svg') !== -1;