Reputation: 57
I use jQuery Confirm 3.3.4 and I want to use the $.fn.confirm
way as described here.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
<p>
<a class="example2-1-1 btn btn-primary" data-title="Goto twitter?" href="http://twitter.com/craftpip">Goto twitter</a>
</p>
<script>
$('.example2-1-1').confirm({
content: "This will take you to my twitter <br> You can access the clicked element by <code>this.$target</code>",
});
</script>
But I would like to put some content in the a-attribute to give it to the confirm-dialog.
For example:
<a class="example2-1-1" href="http://twitter.com/craftpip" myContent="some new content">Goto twitter</a>
Is there a way to do that?
Upvotes: 0
Views: 44
Reputation: 5519
In addition to your answer, you can use a more generic way and fetch the value of any attribute and not a data-*
one:
$('.example2-1-1').confirm({
content: $(this).attr("data-Content"), // or any other attribute you have
width: 'auto'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
<a class="example2-1-1" href="http://twitter.com/craftpip" data-Content="Wollen Sie wirklich zu Twitter?">Goto twitter</a>
Upvotes: 0
Reputation: 57
$('.example2-1-1').confirm({
content: $(this).data("Content"),
width: 'auto'
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.4/jquery-confirm.min.js"></script>
<a class="example2-1-1" href="http://twitter.com/craftpip" data-Content="Wollen Sie wirklich zu Twitter?">Goto twitter</a>
Upvotes: 1