I have the following code from a JavaScript file:
$("body").on("click",".edit",function(){
var list=$(this).closest("a").data("list");
var seira=$(this).closest("a").data("order");
//alert(navbar_edit[list][seira]);
var edit=navbar_edit[list][seira];
navbar_edit[list][seira]=prompt("Change property",edit);
exportLists();
});
$("body").on("click",".edit-save",function(){
var property=$(this).closest("a").text();
property=property.substring(0,property.length-4);
alert(property);
var list=$(this).closest(".list-group").attr("id");
list=list.substring(list.length-1);
navbar_edit[list].push(property);
exportLists();
});
As you can see, I use $("body")
3 times to execute 3 different actions. Is there any way to use it only once so I can reduce my code?
$("body")
and two click handlers. \$\endgroup\$exportLists()
do, and is it related to all this jQuery selection stuff? \$\endgroup\$