You do not show me the tooltip

1

Well, that's it, I'm trying to show a tooltip in an input field and it does not show it to me, I do not know where I'm having the error.

//Javascript (JQuery)
$(function test()
{
    var valor = $("#nombre").val();
	if( valor == null || valor.length == 0) {
	  $("#nombre").tooltip({
		 content: "texto de prueba"
	  });
	  return false;
	} else { return true;}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<input type="text" id="nombre" onclick="test();">

I'm sure it's silly but I can not visualize it.

    
asked by Cifu 08.02.2017 в 20:38
source

2 answers

4

Missing the necessary libraries, and the title attribute in the input

function test()
{
	var valor = $("#nombre").val();
	if( valor == null || valor.length == 0) {
	$("#nombre").tooltip({
		content: "texto de prueba"
	});
	     return false;
	     } else { return true;}
	};
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Tooltip - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<input id="nombre" title="faltaba title" onclick="test();">
    
answered by 08.02.2017 / 21:34
source
1
  • Verify that JQuery is the first library you call.
  • The code you execute must be after the call to JQuery.
  • In your code $(function test() replace it with function test() without the dollar sign at the start.
  • answered by 08.02.2017 в 21:14