Search code examples
jqueryclickjqtransform

click event using jqTransform


How can I get selected value from a jqTransform select box?

HTML:

<form>
    <select>
        <option value="1">A</option>
        <option value="2">B</option>
        <option value="3">C</option>
    </select>
</form>

JS:

$('form').jqTransform();

$(document).on("click", ".jqTransformSelectWrapper ul li a", function()
{
    alert("ok");
});

The sample code above is not firing and I don't kown why :(

jsfiddle: http://jsfiddle.net/matias/ghFdC/

EDIT 1: I should point out that the select box is added dynamically and then I apply the plugin, hence the .on()

EDIT 2: I prefer the use of .on() instead of .bind(). From jQuery: "As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document."


Solution

  • The problem in this case is with jquery.jqtransform.js, in the line 273 this use:

    $ul.find('a').click(function(){
    

    and in the end use return false, then this call by jquery to

    event.preventDefault();
    event.stopPropagation();
    

    and then stop there...

    Apparently this stop the delegate on, but that doesnt happen with this:

    $('form').jqTransform();
    $('.jqTransformSelectWrapper ul li a').bind('click',function(){
        alert('ok');
    });
    

    if you preffer you can remove that return false (jquery.jqtransform.js) and i think on will work