interactive symbols in a reorganizable tree structure

I have been developing a customizable tree list for our users to arrange their website content. It allows them to add and rearrange pages by dragging and dropping. Each list item includes the page name and three icons (lock, visible, and edit).

The challenge I am facing is making these icons clickable. Instead of triggering a click event on the icons, they initiate the dragging action of the list item.

For creating the nestable list, I am utilizing dbushell's Nestable plugin: https://github.com/dbushell/Nestable

This is a snippet from my nestable list:

 <div class="dd">
    <ol class="dd-list">
        <li class="dd-item" data-id="1">
            <div class="dd-handle">Item 1<img class="icon" src="iconpath" style="float:right;"></div>
        </li>
        <li class="dd-item" data-id="2">
            <div class="dd-handle">Item 2<img class="icon" src="iconpath" style="float:right;"></div>
        </li>
        <li class="dd-item" data-id="3">
            <div class="dd-handle">Item 3<img class="icon" src="iconpath" style="float:right;"></div>
            <ol class="dd-list">
                <li class="dd-item" data-id="4">
                    <div class="dd-handle">Item 4<img class="icon" src="iconpath" style="float:right;"></div>
                </li>
                <li class="dd-item" data-id="5">
                    <div class="dd-handle">Item 5<img class="icon" src="iconpath" style="float:right;"></div>
                </li>
            </ol>
        </li>
    </ol>
</div>

Following dbushell's guide, I invoked $('.dd').nestable(); to enable sorting and nesting functionality for this tree.

Here is the click function that is causing issues:

$(".icon").click(function() {
 console.log("click");
});    

I hope I have provided sufficient context. If not, please let me know. Additionally, I am new to programming and StackOverflow, so any guidance on improvements would be appreciated.

Answer №1

Have you experimented with stopPropagation method? Give it a try:

 $(".lock").click(function(e) {
    e.stopPropagation();
    console.log("clicked");
 }); 

Take a look at this Sample Fiddle ... See what happens when you comment out the stopPropagation

Answer №2

While exploring in devtools on Chrome, I discovered that moving the icon outside of the handle was necessary.

<div class="dd">
    <ol class="dd-list">                      place the icon  at this location
        <li class="dd-item" data-id="1">  <----
              <div class="dd-handle">Item 1<img class="icon" src="iconpath" style="float:right;"></div>
        </li>
        <li class="dd-item" data-id="2">
            <div class="dd-handle">Item 2<img class="icon" src="iconpath" style="float:right;"></div>
        </li>
        <li class="dd-item" data-id="3">
            <div class="dd-handle">Item 3<img class="icon" src="iconpath" style="float:right;"></div>
            <ol class="dd-list">
                <li class="dd-item" data-id="4">
                    <div class="dd-handle">Item 4<img class="icon" src="iconpath" style="float:right;"></div>
                </li>
                <li class="dd-item" data-id="5">
                    <div class="dd-handle">Item 5<img class="icon" src="iconpath" style="float:right;"></div>
                </li>
            </ol>
        </li>
    </ol>
</div>

I also had to implement Danko's solution as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with jQuery Master-Detail dropdown list selection

Having trouble isolating the code in this jsfiddle script. Despite my efforts, it seems that isolation is not working as expected and Firebug isn't showing any errors on the console: <!DOCTYPE html> <html lang="en"> <head> ...

Unlock the Potential of Bootstrap5 Carousel: Mastering Icon Movement

I'm utilizing the carousel from Bootstrap 5, and here is the image. https://i.sstatic.net/dpmjf.jpg The previous and next icons are overlapping with the text. I would like to reposition them, if possible, just above the upvote/downvote buttons. Howe ...

Regularly check in with the server via ajax calls

I have a page that needs to send periodic "background" ajax requests after it is loaded. These requests should be sent at specific time intervals. Would using cron be the best option for this task, considering that I have never used it before? Are there a ...

wordpress widget that triggers a function when a click event occurs on jquery

I'm facing an issue where this function works perfectly in my header, but seems to have no effect when used in a widget $("#myID").click(function(){ var name = $("#name").val(); var phone = $("#phone").val(); console.log(name +" "+ phone) ...

What is the best way to determine if a checkbox has been selected in ExtJS?

I have a panel with a checkbox inside it. I am trying to figure out how to check if the checkbox is selected or not using an external function. Can someone please assist me with this? this.currentManagerPanel = new Ext.Panel({ border: false, wid ...

Step-by-step guide on aligning an image to the left of text in a Material UI table column

After experimenting with inline styling, I attempted to move the images next to the text in a specific column. However, there are some rows where the images overlap or the text is positioned too far to the right, as shown in this image: https://i.stack.im ...

Conceal and reveal content using jQuery

I'm struggling with creating a functionality to hide and show content when a user clicks on a button (checkbox). I've written some code but it's not working as expected. The issue is that the content doesn't hide when the checkbox is cl ...

Creating and deleting HTML elements in a dynamic array format

My current approach involves utilizing jQuery and JavaScript for the purpose of dynamically adding and removing HTML elements. Specifically, I am focusing on the removal of particular HTML elements. The code snippet is as follows: $(document).ready(fun ...

Chrome field history is causing text input fields to malfunction

When using a regular text input field, I typically expect to see a history of my past entries by double clicking on it in Chrome. However, we have some fields rendered with Angular JS on a page that do not display any history items when double clicked. I ...

Discovering the name of an object property by locating its corresponding id

I am working with a basic JSON data structure where I need to retrieve the name from an object by comparing its ID. For example, if I have the number 2, I need to check if it matches any object's ID. If the ID is equal to 2, then I must fetch the corr ...

Guide on resolving a "res is not defined" issue in Node.js

I've been struggling to test the controller logic for a user validation module, but I keep encountering an error that says "res is not defined" even after trying to define it. How can I properly define it so that it runs through the condition statemen ...

A guide on utilizing Material UI Fade for smoothly fading in a component when a text field is selected

I am facing an issue with a text field input and a helper component. My goal is to have the helper component fade in when a user focuses on the input field. The helper component is wrapped as follows: <Fade in={checked}> <DynamicHelperText lev ...

Tips on avoiding the accumulation of event handlers when dealing with click events triggered by the document selector in jQuery

I am currently working on a project that involves using AJAX to load various pieces of HTML code. This is done in order to properly position dynamic buttons within each portion of the HTML content. In my case, I need to trigger click events on the document ...

What is the best way to bundle a node module with the choice of adding submodules?

I am in the process of developing a JavaScript library that consists of a central core module and multiple optional submodules that enhance the functionalities of the core module. This library is specifically designed for the browser environment, utilizing ...

Utilizing JSON with ASP.NET WebForms

Is it recommended to use JSON, JQuery & ASP.NET 2.0 webforms together or is it better suited for MVC with ASP.NET 3.5 & 4.0? When incorporating JSON, should I utilize gridviews and repeaters controls for binding JSON data or should I create custom tables f ...

Tips for eliminating the PHP form redirection issue

Having trouble with data insertion in MySQL and getting redirected to the PHP file after. Not ideal! Any suggestions on how I can display error or success messages within the same HTML file? index.html <form id="form" action="add_article.php" method=" ...

Error retrieving resource: server returned a 404 status code indicating file not found for javaScript and CSS files

I can't seem to get my css and js files to load on the server. Here is how my file structure looks like: GAME_Folder HTML doctype html head link(href='https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap' rel='sty ...

What is the method to make a String bold when sending it through a messaging service?

Here is the structure of my service: import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class MessageService { messages: string[] = []; add(message: string) { this.messages.push(message); ...

Tips for storing multiple pieces of text in HTML5 local storage

I have been working on creating functions and input boxes within a table to display data upon page reload. However, I am encountering difficulties in understanding how to store multiple inputs in local storage and then loop through them to show all the d ...

I am currently facing a challenge with Bootstrap, as I am trying to design a webpage for small devices using a 1:4:1 format, but I am struggling to get it right

column 1 and column 3(left and right cols) have successfully passed the test case, but not column 2 (the middle one) that I have commented on in the code. Please help. Thank you. The problem has certain conditions that would have been easier to understa ...