Search code examples
javascriptjqueryhtmllistviewhref

Clicking on an item in the listview do not run the onclick


I have a ListView of Jquery.

Clicking on each item passes to another page:

This is the list:

I fill it in the code as follows:

function FillList() {
    var UL= $('#MyList');
    for (var i = 0; i < 3; i++) {
        var newLI = document.createElement("LI");
        UL.append(newLI);
        newLI.innerHTML = '<a href="NewPage.html" data-transition="slide" 
                           onclick="DoSomething('+i+');" >
                               <p> item number:'+i+'</p>
                          </a>';


    }
    $('#MyList').slideDown('slow');
}

The function DoSomthing:

function DoSomething(numberLi)
{
  alert(numberLi);
}

Function DoSomething not run when click on an item in the list,

it makes the move to another page without first entering the function DoSomething

why?

UPDATE:

Even when the code looks like this:

        newLI.innerHTML = '<a href="NewPage.html" data-transition="slide" 
                           onclick="alert('aaa');" >
                               <p> item number:'+i+'</p>
                          </a>';

The alert does not appear..


Solution

  • The problem was solved

    I sent him a space variable and therefore the function did not work for me ..

    It was not in question so you could not know that,

    thanks anyway