2
<li class=" active">
<input class="check-shopby" type="checkbox" onclick="$(this).next().click()" checked="checked">
    <a class="checked" href="http://mysite/~dev433/products//cooking/cook-tops.html" onclick="$(this).previous().checked = false;" style="cursor: pointer;">
        <img width="150" alt="" src="site/media/wysiwyg/attribute_Sets_images/Fagor-CE9-20-1.jpg">
        <span> Electricity (74) </span>
    </a>
    <a onclick="otherjavascriptfunction" href="/somewhere">link</a>
</li>

Ok, this is my content inside a li item, when i go under certain condition i want it(the li item itself and all other clickable items inside) to be completely unclickable, if even possible some non-clickable(disabled) sign.

This is what i tried but it replaces my content, $("div li a").replaceWith(function() { return $(this).text(); });

4
  • 1
    when i go under certain condition - What condition and when this will be checked? Commented Aug 21, 2015 at 7:51
  • condition is i'm counting all the checkboxes. on remaining last item i don't allow user to click the last item. Commented Aug 21, 2015 at 7:53
  • Provide the whole event if possible as I said when you want to check this condition? Commented Aug 21, 2015 at 7:54
  • 1
    You can use pointer-events: none; on all link elements and to disable whole li, add a class to li with some opacity. Commented Aug 21, 2015 at 7:54

2 Answers 2

2

You can add clickEventListener that will be listening on li element in captureMode

If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTargets beneath it in the DOM tree. Events which are bubbling upward through the tree will not trigger a listener designated to use capture.

var disableClicks = document.getElementsByClassName("disable-inner-clicks");
disableClicks.forEach(function(element){
   element.addEventListener('click', function(e){
      e.preventDefault();
      e.stopPropagation();
   }, true);
});

Then for any element you want to disable clicks, just add class = disable-inner-clicks

<li class="active disable-inner-clicks">
  ....
</li>

No matter what content inside, clicks are disabled, and when your condition is fulfilled you just add the class to the element

Sign up to request clarification or add additional context in comments.

Comments

1

Simple solution. Set all children disabled and remove the click event.

$('li.active *').prop('disabled', true).off('click');

1 Comment

didn't seem working here, rather than this @patel comment above pointer-events: none; looks working for now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.