I’m trying to make an input in html, where any inputed word will be searched in and then marked. Taking the input value and giving it to variable in js is ok, but then i can’t use that variable as search item, where is my mistake?
$(document).ready(function(){
$("#Input").change(function() {
var str = $("#Input").val();
$("div:contains(str)").css("text-decoration", "underline");
});
});
if i change :contains(str) for :contains(“Any string”) it does work better, but i can’t make variable work, help plz 🙂
Solved
Everything works perfectly ok, now i am stucked about mobile phones, i’ve tried from PC it worked well, but my phone could not execute the code, do mobile phones need additional button there or there is no chance to execute js for my mobile phone? (Nokia E5)
Just in case if anybody want to check, here is the link
You need to use string concatenation to create a selector with your variable
str, otherwise the selector is looking for the literal text “str”.… and welcome to StackOverflow.