Reputation: 40
i create dynamically a Modal and set dynamically the href attribute of a link in the Modal. (i cant set the href when i create the modal)
If i click on the Button it doesn't open the Link of the Button
My Button shown like this in the Modal
<a data-temp_code="123456" class="btn btn-sm c_button js-printpdf-offer" type="button" target="_blank" href="http://someurl.com/docs/getArticle.php?code=123456"><i class="glyphicon glyphicon-print"></i> Open Link</a>
Anybody know where is the problem?
I created a Jsfiddle and there it works and i dont know why?!
Upvotes: 0
Views: 665
Reputation: 2476
After a first look, it's something with our script, the onclick function doesn't append your href to the <a>
's href.
Try to follow these to debug your code:
1- $(document).ready(function(){.....});
2- Try to console.log the href after you append it: $('.js-new-link').attr()
3- Make sure there is no other function that overrides the event by returning false or preventDefault
4- Place your script at the end of the <body>
tag
Upvotes: 1
Reputation: 40
i have a "click" - event on the link too... i comment it out and after that it works... but i don't know why?! this is the code of the click event?
$(document.body).on('click', '.js-printpdf-offer', function(event) {
event.preventDefault();
if($('#onlyInternModal.in').length > 0) {
$('#onlyInternModal.in').modal("hide");
}
var temp_code = $(this).data("temp_code");
var make = $('.js-hersteller').val();
var model = $('.js-typ').val();
var model_id = $('.js-model-id').val();
var caption = '';
$.ajax({
type: "POST",
url: "ajax/saveAction.php",
data: {
temp_code:temp_code,
make:make,
model:model,
model_id:model_id,
caption:caption,
},
success: function(data) {
}
});
});
Upvotes: 0