Note that there are some explanatory texts on larger screens.

plurals
  1. POfind element by attribute, set different attribute of the found element
    primarykey
    data
    text
    <p>this might be confusing to others, as it is to me, but I was wondering if I could use jquery to find an element based on a unique attribute value and then set the value of a different attribute. Basically i'm trying to make a static page seem dynamic through custom attributes.</p> <p>Some html is;</p> <pre><code>&lt;div class="Sell" style="width: 47px;"&gt;&lt;input type="checkbox" fund-id="1" id="chkSell" class="_1"/&gt;&lt;/div&gt; &lt;div class="Buy" style="width: 47px;"&gt;&lt;input type="checkbox" fund-id="1" id="chkBuy" class="_1"/&gt;&lt;/div&gt; &lt;div class="BuySelllbl" style="width: 10px;"&gt;&lt;label id="lblBuySell_1" fund-id="1"&gt;&amp;nbsp;&lt;/label&gt;&lt;/div&gt; </code></pre> <p>I have set the "fund-id" attribute to "1" to show that all of these are connected for 1 record, subsequent records will be 2, 3, 4 etc..</p> <p>I have a function where depending on the checkbox that is checked I will display an S for Sell or a B for Buy in the label above. My function looks like this;</p> <pre><code>$("#chkSell").live('change',function(){ var y = $(this).attr("class"); var x = "lblBuySell" + y; var fundID = $(this).attr("fund-id"); //alert(fundID); if(this.checked){ var lbl = $("label").find("[fund-id='" + fundID + "']"); alert(lbl); $(lbl).html("S"); //$("#" + x).html("S"); $("#" + x).attr("style","color: red;"); }else{ $("#" + x).html("&amp;nbsp;"); } }); </code></pre> <p>What I want to be able to do is take the fund-id from the checkbox, find the label with the same associated fund-id and set just that labels .html attribute to be an "S" and to be red as you can see below. Is this possible or am I just out of whack with my thought process? any help is greatly appreciated. Thank you, NickG</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload