jPhizzle
jPhizzle

Reputation: 497

Use jquery Input value window prompt in html

What I'm trying to do is have a window prompt / alert box pop up with a text input. I want the value of the text in my jQuery code to be used in place of the word YOU in the a tag in my html document.

jQuery code I'm using

$(document).ready(function() {
    var userName = window.prompt("Please Enter Your Name", "Text");
});

My html

<body>
  <center><h1 class="Logo">Welcome to<br>an epic story adventure<br>starring <a>YOU!</a></h1></center>
  <p></p>
  <script type="text/javascript" src="js/jquery.js"></script>
  <script type="text/javascript" src="js/name.js"></script>
</body>

so basically, I wanna replace YOU! with the input value of the window prompt

Upvotes: 0

Views: 3608

Answers (1)

j08691
j08691

Reputation: 208032

You'd just need to add this line after the userName JavaScript line you have:

$('h1.Logo a').text(userName);

On a side note, don't use the <center> element; it's not valid anymore. Use CSS instead. Also, a <span> might be more appropriate than an <a> tag in your example.

Upvotes: 1

Related Questions