خرید بک لینک

Vote count: 0

How do I use the data-attribute to pass a dynamically generated id from a rails app to jQuery? When I try, the value retus undefined unless I just send it to an alert box.

This code:

$(document).on "page:change", ->
    $('#debug_link_id').click ->
        alert $(this).data('dynamic_id)

Shows the dynamic_id in the alert box.

However, using the same selector, this code:

$(document).on "page:change", ->
    jqVar = $(this).data('dynamic_id')
    $('#link_id').click ->
        alert jqVar

Shows "undefined" in the alert box. [using .attr('data-dynamic_id') gives the same results]

Kindly tell me:

  1. Why the first code works and the second doesn't
  2. If there is a better strategy for pulling dynamic id's into jQuery
asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 23 فروردين 1395 ساعت: 2:24

صفحه بندی