0

I'm trying to use a VARIABLE as a ATTRIBUTE value...

I have :

var text = "Hello!";

and the HTML is :

<li class="pro" id="text"> ---> (I want the attribute ID to equals the TEXT variable)

How can I make this work?

Thank you


EDIT

I will be more specific in my question.

Here's what I really have :

<li class="product" name="RD-101" price="18"  minimum="4" gap="4"> 
                         <a class="product-image fancybox" href="images/product_big.jpg" title="Picture 4">
                             <img src="images/product_2.png" alt="Preview"/>
                             <div class="text-overlay">
                              <p class="product-heading">Description</p>
                               Enseignes résidentielles imprimées sur 2 panneaux 4 mm 36” x 24” collés dos à dos.
                             </div>
                         </a>
                         <p class="product-heading">RD-101 (Simple)</p>
                         <a href="#" id="test" class="product-buy">Ajouter au panier</a>
                         <p class="product-meta">Double de pareterre 32x24</p>
                         <div class="product-price">18<span class="product-currency">$</span></div>

                    </li>

As you can see I use custom attributes that are set in my Javascript code. I want to know how to set (for instance)...the PRICE attribute to a VARIABLE VALUE instead of the number "18" like it is right now in what I pasted up there.

I was thinking of something like -->

<li class="product" name="RD-101" price="MY_VARIABLE_HERE"  minimum="4" gap="4"> 
larin555
  • 1,669
  • 4
  • 28
  • 43
  • 2
    `li` elements do not have a `name` attribute. use `data-name` if you want to store custom data. – ThiefMaster May 30 '12 at 17:03
  • Ok. But let's say the attribute is "id"...How can I make it equals the TEXT variable value? That's what I need to know – larin555 May 30 '12 at 17:07
  • @user1388136 Since your update, I'm now confused. Are you saying you want the ID of this particular
  • object to be the same as the content of the "text" variable? So in your example, the desired outcome is
  • ? It seems a bit of a strange request
  • – freefaller May 30 '12 at 17:13