jquery - How do I change left with element label? -


my code this:

<label><li><input name="skills[]" class="skills" value="1" type="checkbox" /></li>a</label> <label><li><input name="skills[]" class="skills" value="2" type="checkbox" /></li>b</label> 

for change (left element) of checked checkbox, use code:

$('input.skills').on('change', function() { if($(this).is(':checked')) {     $(this).parents('li').append('<span class="text">add</span>'); } else {     $(this).parents('li').find('.text').remove();    }   $(this).animate({left:'500'},1000);   }); 

however don't change label location, change checked check box location.

you can move entire li. http://jsfiddle.net/pyuau/

html

<ul class="skill-holder">     <li><input name="skills[]" class="skills" value="1" type="checkbox" /></li> <li><input name="skills[]" class="skills" value="2" type="checkbox" /></li> </ul> 

css

.skill-holder > li {     position: relative; } 

js

$('.skill-holder').on('change', '.skills', function() {     var $this = $(this),         parent = $this.closest("li"),         moved; if(moved = $this.is(':checked')) {     parent.append('<span class="text">اضافه</span>'); } else {     parent.find('.text').remove();    }       parent.animate({left:moved ? 500: 0},1000);   }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -