Rubel Ctg Rubel Ctg - 1 year ago 79
jQuery Question

how work id^=value in javascript

$("[id^='Qty-']").each(function() {

itemElementId = $(this).attr('id');
var productId = 0;
productId = itemElementId.replace("Qty-", "");

postArr[index] = { ProductId: productId, Qty: $(this).val() }

I can't understand $("[id^='Qty-']") meaning. why use this. please help me

Answer Source

Some JQuery basics:

The selector $("[id^='Qty-']") will search for all the elements having attribute Id having value starting with Qty-

here's an example how this selector is looking for id values Qty- and displaying the content of td

<script src=""></script>
  <td id="Qty-1">Qty1</td>
  <td id=Qty-2>Qty2</td>

For more information and learning, please refer this link on attribute selectors.

Hope this helps..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download