I am trying to pull some content with ajax and at my first step i have fallen wrong .
Here is my simple code
<a href="page.php" data-content="ajax"</a>
and my js is
(function($){
'use strict';
var ajaxcontent = $('[data-content="ajax"]'),
ajaxUrl;
ajaxcontent.each(function(index, el) {
var ajaxUrl = $(this).attr('href');
});
console.log(ajaxUrl);
})(jQuery);
but it shows undefined
in console.
I have also tried with --
<a href="" data-content="ajax" data-url="page.php"></a>
(function($){
'use strict';
var ajaxcontent = $('[data-content="ajax"]'),
ajaxUrl;
ajaxcontent.each(function(index, el) {
var ajaxUrl = $(this).data('url');
});
console.log(ajaxUrl);
})(jQuery);
result is same .