0

I'm working on a WordPress template. The following code works fine with "Click Function". But now I want to add keyboard shortcut to this function, so that visitor will get choice for both mouse click and keyboard shortcut to perform same function. I tried to apply this method after e(".bookmark").live("click", function () { line but it didn't solve the problem, Instead it broke the button too.

A little help will be appreciated. Thank you.

function whatever_do_js(e, t) {
    loadingImg = e.prev();
    loadingImg.show();
    beforeImg = e.prev().prev();
    beforeImg.hide();
    url = document.location.href.split("#")[0];
    params = e.attr("href").replace("?", "") + "&ajax=1";
    if (t) {
        jQuery.get(url, params, function (t) {
            e.parent().html(t);
            if (typeof whatever_after_ajax == "function") {
                whatever_after_ajax(e)
            }
            loadingImg.hide()
        })
    }
}

jQuery(document).ready(function (e) {
    e(".bookmark").live("click", function () {
        dhis = e(this);
        whatever_do_js(dhis, 1);
        return false
    })
})
Community
  • 1
  • 1
wp student
  • 755
  • 9
  • 24

2 Answers2

0

Try

$(selector).bind("click keydown", function () {
    // Your code goes here.
}
Parkash Kumar
  • 4,710
  • 3
  • 23
  • 39
  • Hello, thank for you little tip. I tried the following code, there are no errors in console but both enter button and click aren't working `jQuery(document).ready(function (e) { dhis = e(this); jQuery(".bookmark").bind("click keydown", function (e) { if (e.type == "keydown" && e.which == 13) fancy_do_js(dhis, 1); return false }) }) ` – wp student Dec 05 '13 at 19:11
0

Maybe this would help you, Bind multiple events to jQuery 'live' method(Bind multiple events to jQuery 'live' method)

Community
  • 1
  • 1
P.Peng
  • 46
  • 4