Can you make SweetAlert work by clicking on a text?

0

I'm making a web page, and until now I used the JS alert.

I had made a text, and, clicking, I jumped an alert. It was of this type:

<a href Onclick="alert("Texto")">Haz click aquí</a>

And I want to know if it can be done with SweetAlert.

Thank you very much!

    
asked by Miquel Puente 21.07.2018 в 20:57
source

2 answers

0

It would seem to use it like this, in this way you do not combine your js code with the html

$("#tagA").on("click", function (){
    swal({
        allowOutsideClick: false,
        title: 'Titulo',
        html: "Texto",
        type: 'success',
    })  
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.25.6/sweetalert2.all.js"></script>

<a href="#" id="tagA">A</a>
    
answered by 21.07.2018 / 21:15
source
0

You could use Jquery to hear a click on the text as follows:

$( document ).ready(function() {
    
     $(".text").click(function(){
		alert("hola");
      //swal("Hello world!");
  
      });
});
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
  
  <title>ejemplo</title>
</head>
<body>

  <p class="text">texto ejemplo</p>
</body>
</html>

and instead of executing the alert it executes the sweetalert sawl

    
answered by 21.07.2018 в 21:19