I guess I am to stupid to get this to work.
I have a shoppingcart which can be splitted in multiple carts, if someone buys items from different sellers. So I create for every seller his own form and table, which IDs are extended by $sellerId. Next step is to count how much elements with class 'delete16' are in the given table, for example with id="cartTable_815".
I can get this to work if I code this:
var n = $("#cartTable_815 div[class=delete16]").length;
But if I want to write myself a function to count the elements with class 'delete16' within a variable table-id I tried this:
$("#cartInner div[class=delete16]").click(function(){
var id = this.id;
removeItem(id);
});
function removeItem(id)
{
var identifiers = id.split("_");
var cartId = identifiers[1];
var itemId = identifiers[2];
var tab = "cartTable_" + cartId;
var n = $("#cartTable_815 div[class=delete16]").length;
alert(n);
}
If I replace #cartTable_815 with tab it does not work.
var n = $("#cartTable_" + tab + "div[class=delete16]").length;
Hope someone can explain me how I have to do this the right way.
Thanks for your time and reading
var n = $("#cartTable_" + tab + " div[class=delete16]").length;