0

I'm trying to match an input value against a data attribute but it doesn't seem to be working. Here's the code:

HTML:

<input value="" data-match="Training">

jQuery:

var wrd = $('.js-search-input').data('match');
$('.js-search-input').on('keyup keydown paste', function () {
    if ($(this).val().toLowerCase() === wrd) {
        $('.search-demo-text').show();
    }
});

Has anyone got any ideas on the best way to match the input value based on the data-* attribute.

jsFiddle: http://jsfiddle.net/JQ8Sa/1

2
  • Except that keyup is not needed, what is wrong with that? Commented Jul 1, 2013 at 14:45
  • @Karl-AndréGagnon - that's what I am not sure about, here's the fiddle: jsfiddle.net/JQ8Sa/1 Commented Jul 1, 2013 at 14:49

1 Answer 1

2

wrd is equal to "Training" in this case. You then compare the value in all lowercase to this string. Since "Training" is not lowercase, it will never match.

Also, your input doesn't have the class js-search-input as the code implies. Though I assume this is in place in your real code.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I updated the fiddle when I noticed that. Much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.