0

I have created a page droppable and am trying to delete the dragged elements. But I have a problem that I don't know how delete the selected elements from the keyboard delete key. here is my code:

$canvasElement.click(function() {
    jQuery('.canvas-element').removeClass('selectedItem');
    jQuery($canvasElement).addClass('selectedItem');
    jQuery('#button').removeClass('delete');
    jQuery('#button').addClass('showButton');
})

jQuery(".deleteButton").click(function () {
jQuery(".selectedItem").remove();
jQuery('#button').removeClass('showButton');
jQuery('#button').addClass('delete');
});

HTML:

<li>
    <p id="button" class="delete"><button class="deleteButton">Delete</button></p>
</li>

CSS:

.selectedItem {
    border: 2px solid #5C3B84!important;
}
.showButton {
    display:block!important;
}
.delete {
    display:none;
}

But I have to delete the element from the keyboard delete key.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Jackson
  • 58
  • 2
  • 10
  • I don't fully understand your question. Do you want to do something when the user presses the delete key on the keyboard? Then a simple keybinding should serve your needs. – buschtoens Jan 10 '12 at 10:43

1 Answers1

0

to delete using keyboard, you must have a plugin called jquery.hotkeys.

Read here Keyboard shortcuts with jQuery for your question.

Or, if you wish only javascript look into same page because there will appear other alternatives to do.

Community
  • 1
  • 1
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221