How To Ignore Shortcode On Html Text Search
I'm looking for a solution to a specific problem: I am trying to use a w3schools dropdown menu with a search option with a combination of a shortcode for countries flags and I need
Solution 1:
WordPress Shortcodes are parsed at at runtime, so you actually need to worry about what the output of those shortcodes is. Likely something like <img src="/path/to/flags/flag-1.png" />
Since you clearly have control over the HTML markup inside the dropdown, I would just wrap the Country in a span, and target that with the JavaScript instead. Take the following snippet for example:
You'll note that it no longer cares about anything else inside the anchor, and instead only cares about the text inside the anchor's span
.
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */functionmyFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
functionfilterFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
div = document.getElementById("myDropdown");
a = div.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
var label = a[i].querySelector('span');
if (label.innerText.toUpperCase().indexOf(filter) > -1) {
a[i].style.display = "";
} else {
a[i].style.display = "none";
}
}
}
.dropbtn{background-color:#4CAF50;color:#fff;padding:16px;font-size:16px;border:none;cursor:pointer}.dropbtn:focus,.dropbtn:hover{background-color:#3e8e41}#myInput{border-box:box-sizing;background-image:url(searchicon.png);background-position:14px12px;background-repeat:no-repeat;font-size:16px;padding:14px20px12px45px;border:none;border-bottom:1px solid #ddd}#myInput:focus{outline:#ddd solid 3px}.dropdown{position:relative;display:inline-block}.dropdown-content{display:none;position:absolute;background-color:#f6f6f6;min-width:230px;overflow:auto;border:1px solid #ddd;z-index:1}.dropdown-contenta{color:#000;padding:12px16px;text-decoration:none;display:block}.dropdowna:hover{background-color:#ddd}.show{display:block}
<h2>Search/Filter Dropdown</h2><p>Click on the button to open the dropdown menu, and use the input field to search for a specific dropdown link.</p><divclass="dropdown"><buttononclick="myFunction()"class="dropbtn">Dropdown</button><divid="myDropdown"class="dropdown-content"><inputtype="text"placeholder="Search.."id="myInput"onkeyup="filterFunction()"><ahref="#about"><iclass="flag a"></i><span>About</span></a><ahref="#base"><iclass="flag b"></i><span>Base</span></a><ahref="#blog"><iclass="flag b"></i><span>Blog</span></a><ahref="#contact"><iclass="flag c"></i><span>Contact</span></a><ahref="#custom"><iclass="flag c"></i><span>Custom</span></a><ahref="#support"><iclass="flag s"></i><span>Support</span></a><ahref="#tools"><iclass="flag t"></i><span>Tools</span></a></div></div>
Post a Comment for "How To Ignore Shortcode On Html Text Search"