0

I don't know pass a id value of php to jquery in moodle. Have a two files index.php and myscript.js

index.php file:

html_writer::tag('button','', array('id' => 'buttonCompile', 'data-url' => $urlbase));

myscript.js file:

$(document).ready(function(){ 
     alert($('#button').attr('id'));

});

i need show the value of 'data-url' in js file

pd: html_writer is a moodle function for write html code, in this case is a button tag.

Jonny
  • 3
  • 1

1 Answers1

2

as the id of your button is buttonCompile, you won't be able to find any items with the id button. You can get the data-url of your buttonCompile attribute in jQuery with the following code:

$(document).ready(function(){ 
     alert($('#buttonCompile').data('url')); 
     //or $('#buttonCompile').attr("data-url")
});

cfr. How to get the data-id attribute?

If however you want to get the id of your button (and there is only one button on your page. You could do it like this:

$(document).ready(function(){ 
     alert($('button').attr('id')); 
});
Community
  • 1
  • 1
Kristof Feys
  • 1,822
  • 1
  • 19
  • 36