Checking If A Html Tag Exist On This Scenario Using Js February 26, 2024 Post a Comment The HTML part looks like this: Logins (including fSolution 1: 1. First question is what can I use to check if this option exist? I know there is a method (myfile.getElementsByTagName("")) but in my case I have a lot of tags that has the tag-name "option".You can use document.querySelector to find the first matching element for any valid CSS selector. It returns the element instance if found, or null if not found. So for instance, from what you've shown of your HTML, you could do this:if (document.querySelector('select[name="metric-name"] option[value="13"]')) { // Yes, it's there } else { // No, it's not } Copy2. If there is a method to check if the option exist, is it [going to] work on this scenario since my option is on the page even though is displayed only when accountId from session is not equal to 5According to what I can find about cfif, the optionwon't be on the rendered page in the browser if that condition is true. So the above would work.Example without the option:if (document.querySelector('select[name="metric-name"] option[value="13"]')) { console.log("Yes, it's there"); } else { console.log("No, it's not there"); }Copy<selectclass="ue-select-box box-model"name="metric-name"><optionvalue="1"selected>Logins (including from CRM)</option><optionvalue="2">Listened to a Call (including from CRM)</option><optionvalue="15">Set up a New Report/Edited a Report</option></select>CopyExample with the option:if (document.querySelector('select[name="metric-name"] option[value="13"]')) { console.log("Yes, it's there"); } else { console.log("No, it's not there"); }Copy<selectclass="ue-select-box box-model"name="metric-name"><optionvalue="1"selected>Logins (including from CRM)</option><optionvalue="2">Listened to a Call (including from CRM)</option><optionvalue="15">Set up a New Report/Edited a Report</option><optionvalue="13">Staff Activity - Deactivate</option></select>Copy Share Post a Comment for "Checking If A Html Tag Exist On This Scenario Using Js" Top Question Firefox, Chrome, Safari Have Grey Background For Mp4 Html5 Video Any video (that I can make) with a white background becomes… Red Border Still Appears On Inputs After Resetting An HTML 5 Form Firefox I have an HTML 5 form! Great, I'm excited! I decide to … Svg Animation And Firefox I'm struggle with SVG animation drawing, which is work … How To Save Html5 Geolocation Data To Python Django Admin? Is it possible to save the javascript html5 geolocation lat… How To Hide/show Tabs Using Jquery I have four tabs.On loading only the first tab is opened an… Form To Iframe Submission - How Do You Reset The Form After File Upload? I have a form that submits the results to an iframe. The su… How To Limit The Html Table Records In Each Page I am populating a table in my jsp which has more than 20 re… How To Display A Python String As Html In Jupyter Notebook In IPython notebook, I used to be able to display a python … How To Add Placeholder Field? I've been trying to add placeholder in input type='… Bounce Animation On A Scaled Object What is the best way to have an object scale and then perfo…