How to find label with particular attribute and it's value
<p>i have a page layout like this</p>

<pre><code>&lt;input id="name" class="mandotary" type="text"&gt;
&lt;label for="name"&gt;Name must be entered&lt;/label&gt;

&lt;input id="code" class="mandotary" type="text"&gt;
&lt;label for="code"&gt;Code must be entered&lt;/label&gt;
</code></pre>

<p>Now i want to hide the label element when page load first. If it has lose the focus and value is null then label should be shown else label should be hidden. I tried this</p>

<pre><code>var inputElementArray = $("input.mandotary");
$.each(inputElementArray, function(index, element){

    var id = $(element).attr("id");
    var label = $("label").attr("for", id);
   // label.hide();

    $(element).focus(function(){
        var next = $(element).next();
        $(element).next().hide();
    }); //end of focus()

    $(element).blur(function(){

        // get value of text area
        var text = $(element).val();
        if (text == "") {
            var next = $(element).next();
            $(element).next().show();
        } //end of if

    }); //end of blur()

}); //end of $(document).ready(fn)
</code></pre>

<p>But the line </p>

<pre><code>var label = $("label").attr("for", id);
</code></pre>

<p>Give me both the labels. I just want that label whose for attribute value is id(name or code). I get the name or code as id in the <strong>var id</strong>. But it finds both the leabes. How can i find that label whose for attribute value is equal to my input element id?</p>

<p>Thanks</p>
