[RESOLVED]bind mouseenter event with class

hi

i bind the mouseenter event with particular class but the eveent does not fire.

this is my code

              $(function () {
                    $(".customindexelement").on(
                        'mouseenter',
                        function () {
                            alert("test");
                        }
                    );
                });

i add the <li> element dynamically with this class. i think thats why it does not fire. how to bind event with dynamically created element using class name;

$(function () {
                    $(".customindexelement").mouseover(
                        function () {
                            alert("test");
                        }
                    );
                });

Try this piece of code .. Reference: http://api.jquery.com/mouseenter/

Hi

Your script will be executed when the document is ready at that point there will not be any element with the class name "customindexelement".

If you wanted to have event(mousenter) to that element you can do that when you are dynamically creating/adding the element.

Checkout the jsfiddle below:

http://jsfiddle.net/8n7Lpbep/

When the element is created, you need to add the events as well at that point.

i think it is not possible cs i don’t want to bind the event with element

i create the elements dynamically

i need to save this html of the container inside my database and need to bring back this html to the same page with the event .

is it possible?

Hi,

How do you add the html from the db ? and to which element you are adding html? Post the code here.

Hi

i add the <li> with some html elements in <ul>

i bind the event with the element.

i push this $(<ul>).html() into database

edit mode i need to bring this html content back and append to <ul>

but the events does not work

hope you understand the problem

Hi

How and what is the logic/code you are using to append the html content to UL?

$(".customUL").html(html from db);

Hi

You can add event as below. Try and let me know.

$(".customUL li").on("mouseenter", function(){
//Logic here.
});

hi this list can contain any number of ul dynamically

no problem i have changed my code

i don’t want to use the html content directly

now i am creating the elements one by one in edit mode

Leave a Reply