0
var inputvalue = $(this).attr('value')
             $('input[value=inputvalue] + label').css({
                    '-webkit-transition': 'opacity 0.4s linear',
                    'opacity': '0'
                });

But it does not work. As expected value=inputvalue does not get that variable but looks for that name. How can i do this?

Thanks a lot :)

2
  • Have you considered using $(this).val() instead of $(this).attr('value')? Oh, and the attribute-equals selector requires the values to be quoted. 'Quotes are mandatory.' Reference: val(), attribute-equals selector. Commented May 13, 2011 at 18:25
  • Can you post your markup? It will help us understand what you are trying to do Commented May 13, 2011 at 18:28

2 Answers 2

3

You need to use some string concatenation here.

var inputvalue = $(this).val();
$('input[value="' + inputvalue + '"] + label').css({
  '-webkit-transition': 'opacity 0.4s linear',
  'opacity': '0'
});
Sign up to request clarification or add additional context in comments.

Comments

0

try this: example

HTML:

<label for="myinput">Label for input</label>
<input id="myinput" />
<button>check</button>
<br />

JS:

$.expr[':'].value = function(obj, index, meta, stack){

    if (meta[3] == $(obj).val())
        return true;    

    return false;
};

$.fn.labelInput = function() {

    if (this && $(this).attr('id'))
        return $('label[for="'+$(this).attr('id')+'"]');

    return null;
}

$('button').bind('click', function(event) {

   var 
       inputvalue = $('input').val(),
       cssOpcions = {
          '-webkit-transition': 'opacity 0.4s linear',
          'opacity': '0'
        };

    $('input:value(' + inputvalue + ')')
        .css(cssOpcions)
        .labelInput().css(cssOptions);

});

Comments

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.