JQuery advanced selector
Is it possible to use comparison statements in jQuery selector method?
eg.
I have a list of divs generated by php that use the same CSS class but have value attributes 1, 2, 3, etc. I also have a text input field with an ID. This field can only accept numbers. I would like to select a div (from a long list) that has a value attribute that matches the value placed in the text input field.
Can I write something like this:
$ ('$ (". SomeClass"). Val () == $ ("input # someId"). Val ()')
???
0
a source to share
3 answers
Take a look at the CSS3 selectors page: http://www.w3.org/TR/css3-selectors/ .
Recommended selector: E [foo = "bar"], as in '.class [value = "' + $ ('# inputId'). Val () + '"]'.
Note: not tested.
+6
a source to share
this is just the standard jquery: attributeEquals selector
<html>
<head>
<title>Just a test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#txtValue').change(function(){
$('.selectMe').css('color', 'black');
$('.selectMe[value= '+$(this).val()+']').css('color', 'red');
});
});
</script>
</head>
<body>
<input type="text" id="txtValue" value=""/>
<div class="selectMe" value="1">one</div>
<div class="selectMe" value="2">two</div>
<div class="selectMe" value="3">three</div>
</body>
</html>
+2
a source to share