jquery contains selector not working for \ (back slash). Please find the code below
Java Script:
$(document).ready(function(){
$("p:contains(Example:\\servername)").css("background-color", "yellow");
});
HTML
<p>Example:\\servername</p>
jquery contains selector not working for \ (back slash). Please find the code below
Java Script:
$(document).ready(function(){
$("p:contains(Example:\\servername)").css("background-color", "yellow");
});
HTML
<p>Example:\\servername</p>
$(document).ready(function() {
$("p:contains('Example:\\\\\\\\\\servername')").css("background-color", "yellow");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Example:\\servername</p>
$(document).ready(function() {
$("p:contains('Example:\')").css("background-color", "yellow");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Example:\\servername</p>
Unfortunately the \ need escaping with another \ and I don't think you can do it with :contains selector.
You can do it using filter()
let p=$("p").filter(function(){
return $(this).text().includes('Example:\\\\servername')
}).css("background-color", "yellow");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Example:\\servername</p>