jQuery.fn.add = function() {
var Bnumber = $(this).find(".B_Add");
if (Bnumber) {
Bcount = parseInt(Bnumber.html()) + 1;
$(this).find("div.B_Add").remove();
$(this).parent().find(".B_List").append('<div class="Badge B_Add">'+ Bcount +'</div>');
} else {
$(this).find(".B_List").append('<div class="Badge B_Add">1</div>');
}
}
I have a contextual menu script running, when i click on one of the options, it calls this function. It’s supposed to see if the active element has this badge or not. If it does, it increments the integer value of the badge. Otherwise, it creates the badge starting at 1. The latter part is easy, the former harder.
I think i’m mixing up element types, and i’m not sure how to use parseInt…
EDIT
Figured it out.
jQuery.fn.add = function() {
if ($(this).find(".Badge").hasClass(".B_add")) {
bCount = parseInt($(this).find(".B_add").text());
$(this).find(".B_add").remove();
$(".OPT .B_list").append('<div class="Badge B_add">'+(bCount+1)+'</div>');
} else {
$(".OPT .B_list").append('<div class="Badge B_add">0</div>');
}
}
Try this.