开发者

stopPropagation onclick not working in nested list

i have the following function to swap images on the click of a ul in a nested list, but it doesnt stop bubbling up the list..

function bimageswap (step) {
    step.stopPropagation;
    realstep = parseInt(step) + 1;
    nextsteps = realstep + 1;
    for (iss = nextsteps;iss <= 5; iss++) {
        document.getElementById("step" + iss).className = 'step' + iss;
        alert(iss);
    }
    document.getElementById("step" + realstep).className = 'step' + realstep + 'a';
/*$("#step2").css(开发者_开发知识库 'background-image', 'images/adtl_prodimg/discs/step1_.png');*/
    return false;
}

it is called like this:

<ul onclick='return bimageswap("4")'>

i tried the return because it is what i found in another answer but it still doesnt work. i would greatly appreciate any help thanks!


The stopPropagation method is in the event object, you can't call it on a string. You are also missing the parentheses, so it would just get the stopPropagation property from the string (which returns undefined) and discard it.

Send the event object from the event handler to the function:

<ul onclick="bimageswap(event, '4');">

Use the event object in the function:

function bimageswap(event, step) {
  event.stopPropagation();
  ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜