using variables as attribute value in selector

by Akram kamal

HTML

<input id="xItemComment" type="text" value="whatup">


<p class="ms-itmhover" iid='985'>
    my text spot 985
</p>

<p class="ms-itmhover" iid='986'>
    my text spot 986
</p>
<p class="ms-itmhover" iid='987'>
    my text spot 987
</p>

JavaScript

jQuery(document).ready(function() {
    var xItemComment = jQuery("#xItemComment").val(); //get current value plus any edits to it
    //jQuery("#ms-itmhover[iid*=xItemID]")
   // alert(xItemComment)

    xItemID = 986;

    jQuery(".ms-itmhover[iid*= '985']").text(xItemComment); //....
    jQuery(".ms-itmhover[iid*= " + xItemID + "]").text(xItemComment);

    iid("987").text("easy")
});

function iid(num){
return $(".ms-itmhover[iid*= " + num + "]")
}