hoping somebody can point me in the right direction. I know there are similar questions, but I havn't found one that deals directly with what I'm trying to achieve. I'm trying to get the id of an input field so I can change font-color.
<div id="red">
<input id="redA" type="text">
<input id="redB" type="text">
<input id="redC" type="text">
</div>
<div id="outerContainer">
<div id="innerContainer">
<div id="blue">
<input id="blueA" type="text" onBlur="check()">
<input id="blueB" type="text" onBlur="check()">
<input id="blueC" type="text" onBlur="check()">
</div>
</div>
</div>
<script>
function check(){
var v=$(this).val();
if ( v=="red" ) { $(this).css({"color":"red"})
if ( v=="green" ) { $(this).css({"color":"green"})
if ( v=="blue" ) { $(this).css({"color":"blue"})
}
</script>
I know this is a bit long winded, but hopefully it can be seen what im trying to do Thanks
you can do it like this
JQuery
here's the jsfiddle for this http://jsfiddle.net/afPrc/109/
the reason your fiddle was not working was because you were not passing the object of your textbox to the function. when you do
$(this)
inside the function, it gets the object ofwindow
instead of thetextbox
.