开发者

Live() function not working with some elements

I'm trying to bind some change events to a select element which has been previously been transformed by jqTransform (http://www.dfc-e.com/metiers/multimedia/opensource/jqtransform/).

As change() function does not work after this transformation, I've followed this excellent advice from Code-Pal. Then I'm trying to apply a click function with the live() event (as future forms will be called with Ajax).

So far I've got this, which does not work:

$("div#caracteristicas-form-wrap div.jqTransformSelectWrapper ul li a").live('click', function(e) {
console.log("Testing");
});

Strangely, this DOES work:

$("div#caracteristicas-form-wrap div.jqTransformSelectWrapper ul li a").bind('click', function(e) {
console.log("Testing");
});

And even this:

$("div#caracteristicas-form-wrap div.jqTransformSelectWrapper").live('click', function(e) {
console.log("Testing");
});

So it's not that jqTransform is still not loaded. For some reason, live() stops working as soon as I'm selecting elements from a list. Any idea of what could be happening?

This is the html code after the jqtransform:

<div class="jqTransformSelectWrapper" style="z-index: 10; width: 194px;">
  <div>
    <span style="width: 179px;">开发者_如何学编程Tarjeta estándar</span>
    <a class="jqTransformSelectOpen" href="#"></a>
  </div>
  <ul style="width: 192px; display: none; visibility: visible; height: 125px; overflow: hidden;">
    <li>
      <a class="selected" index="0" href="#">Tarjeta estándar</a>
    </li>
    <li>
      <a index="1" href="#">Tarjetas cantos redondos</a>
    </li>
    <li>
      <a index="2" href="#">Tarjetas doble</a>
    </li>
    <li>
      <a index="3" href="#">Tarjeta PVC</a>
    </li>
    <li>
      <a index="4" href="#">Tarjeta adhesiva</a>
    </li>
  </ul>

  <select id="id-subproducto" class="jqTransformHidden" name="subproducto" style="">
    <option value="1">Tarjeta estándar</option>
    <option value="2">Tarjetas cantos redondos</option>
    <option value="3">Tarjetas doble</option>
    <option value="4">Tarjeta PVC</option>
    <option value="5">Tarjeta adhesiva</option>
  </select>
</div>

Thanks in advance!


I dont have exactly the same selectors but it all seems to be working:

http://jsfiddle.net/HenryGarle/DeYH2/1/

$("div#caracteristicas-form-wrap div.jqTransformSelectWrapper ul li a").live('click', function(e) {
   alert("Testing");
});

Edit: Updated to use the same selectors


If you're having trouble with jQuery live you might want to check out delegate instead.

Also have a look at Why You Should Never Use jQuery Live


Well guys, after struggling with jqTransform for too many projects, I've switched to UniformJS. Working with it is easier, my life is nicer, the colors in the sky are brighter and girls smile et me when I'm walking down any street.

I recommend it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜