I'm not able to get the data attribute from a button element.

<button
 class="btn btn-solid navigate"
 value="2"
 data-productId={{$product->id}}
 id="size-click"
 >
 Next
</button>

Then I attempt to get it like so:

  $("#size-click").click(() => {
    let width = $("#prod-width").val();
    let height = $("#prod-height").val();
    var prodId = $(this).data("productId");

    console.log('this is prodId');
    console.log(prodId);

    const data = {
      prodId: prodId,
      step: 'Size',
      width: width,
      height: height,
    }

    postDataEstimate(data);

  })

I'm also trying this:

var prodId = $(this).attr('data-productId');

Can you let me know what I'm missing?

I'm not able to get the data attribute from a button element.

<button
 class="btn btn-solid navigate"
 value="2"
 data-productId={{$product->id}}
 id="size-click"
 >
 Next
</button>

Then I attempt to get it like so:

var prodId = $(this).data("productId");

console.log('this is prodId');
console.log(prodId);

I'm also trying this:

var prodId = $(this).attr('data-productId');

Can you let me know what I'm missing?

I'm not able to get the data attribute from a button element.

<button
 class="btn btn-solid navigate"
 value="2"
 data-productId={{$product->id}}
 id="size-click"
 >
 Next
</button>

Then I attempt to get it like so:

  $("#size-click").click(() => {
    let width = $("#prod-width").val();
    let height = $("#prod-height").val();
    var prodId = $(this).data("productId");

    console.log('this is prodId');
    console.log(prodId);

    const data = {
      prodId: prodId,
      step: 'Size',
      width: width,
      height: height,
    }

    postDataEstimate(data);

  })

I'm also trying this:

var prodId = $(this).attr('data-productId');

Can you let me know what I'm missing?

Then I attempt to get it like so:

var prodId = $(this).data("productId");

console.log('this is prodId');
console.log(prodId);

Then I attempt to get it like so:

  $("#size-click").click(() => {
    let width = $("#prod-width").val();
    let height = $("#prod-height").val();
    var prodId = $(this).data("productId");

    console.log('this is prodId');
    console.log(prodId);

    const data = {
      prodId: prodId,
      step: 'Size',
      width: width,
      height: height,
    }

    postDataEstimate(data);

  })

Unable to get data attribute from button element via Jquery

I'm not able to get the data attribute from a button element.

<button
 class="btn btn-solid navigate"
 value="2"
 data-productId={{$product->id}}
 id="size-click"
 >
 Next
</button>

Then I attempt to get it like so:

var prodId = $(this).data("productId");

console.log('this is prodId');
console.log(prodId);

I'm also trying this:

var prodId = $(this).attr('data-productId');

Can you let me know what I'm missing?

Disilab Q&A communities are different.
Here's how

bubble
Expert communities.

This is just a simple text made for this unique and awesome template, you can easily edit it as you want.

vote
The right answer. Right on top.

This is just a simple text made for this unique and awesome template, you can easily edit it as you want.

check
Share knowledge. Earn trust.

This is just a simple text made for this unique and awesome template, you can easily edit it as you want.