fidel fidel - 5 months ago 24
HTML Question

increment class value onclick javascript

im trying to increment class value on click. how can i achieve this using this code?

Generate New Div

<div class="container">
<div data-bind="foreach:items" class="fix_backround">
<div href="#" class="item" data-bind="draggable:true,droppable:true">
<span data-bind="click:$parent.remove">[x]</span><br/><br/>
<center><span class="text" data-bind="text:$data"></span><input class="edit_text"/></center>

is it even possible to increment class="item" example class="item1" item2 item 3 exc increment by one every time draggable is created


You could do something like this to add 'item1', 'item2', etc. for each draggable added.

var count = 1;

    init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
        $(element).addClass('item' + count);

(Just keep in mind that since you're already using an MV* framework, you most likely can avoid having to do things like enumerate classes)