Skip to content

How can I get data-id from multiple elements with single onclick?

as the title says I have multiple buttons which they have data-id. I want to open fancybox modal by getting the clicked buttons data-id. Each element on click will open their own modal. I can’t use class selector because this function is attached to somewhere else, and I know that $(this) here doesn’t mean clicked element.

Thank you for your help.


  function get_cookie_param(){
    function lorem() {
      var dataId = $(this).data("lorem");
        src: dataId,
        type: "iframe",
        opts: {
          toolbar: false,
          smallBtn: true,
          iframe: {
            preload: false,


<a href="#" onclick="get_cookie_param();" data-lorem="products/camera.html" class="btn-lorem"></a>


function get_cookie_param(ele) {
  var dataId = $(ele).attr("data-lorem");
<script src=""></script>

<a href="#" onclick="get_cookie_param(this);" data-lorem="products/camera.html" class="btn-lorem">Element</a>