IVIajid
IVIajid

Reputation: 190

jquery change value of input with a html tag

I want to change the value of my submit input. but It is not just a plain text. for example the value should be like this

Submit query

Send code

but the problem is when I put a br tag between texts, my html code will print exactly. It is possible to change value with query but with printing every texts even html code with that ...

$('input[type=submit]').val('submit<br />send code');

Upvotes: 0

Views: 72

Answers (3)

Rory McCrossan
Rory McCrossan

Reputation: 337560

You cannot put HTML code in to the value of an input button. However, you can set HTML in a button with type="submit" applied:

$('button').click(function() {
    $(this).html('submit<br />send code');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Original value</button>

Upvotes: 1

j08691
j08691

Reputation: 207861

Use \n instead as your break

$('input[type=submit]').val('submit\nsend code');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="submit" />

Upvotes: 1

Quentin
Quentin

Reputation: 943143

No.

Form controls hold only plain text.

You can put markup in a submit button by using a <button> element instead of an <input> element (then you need to use use .html() instead of .val() to change it with JavaScript).

Upvotes: 1

Related Questions