Reputation: 63
i have this input tags
<div id="tag" >
<tags-input v-model="tags" id="meta_keyword" ></tags-input>
</div>
when i insert word,it look like this:
i try this code this code to get this input value(words inserted),
var meta_keyword_it=$('#meta_keyword').val();
alert(meta_keyword_it);
but i dont work,it alert empty!!!
Upvotes: 1
Views: 3814
Reputation: 788
You can use the following code:
var meta_keyword_it=$('#meta_keyword').text();
alert(meta_keyword_it);
Just change val()
by text()
.
If it will not work then you need to inspect created tag with some input text. I think now you are just showing empty input tag.
Upvotes: 1
Reputation: 3591
you should have to replace val
to text
.val()
works on input elements (or any element with a value attribute?) and .text()
will not work on input elements. .val()
gets the value of the input element -- regardless of type. .text()
gets the innerText (not HTML) of all the matched elements: see more at here.
function check(){
var val = $("#meta_keyword").text();
console.log(val);
}
check();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div id="tag" >
<tags-input v-model="tags" id="meta_keyword" >Abcd , xyz </tags-input>
</div>
Upvotes: 1
Reputation: 12152
You have to use .text()/.html()
because does not have value property
var meta_keyword_it=$('#meta_keyword').text();
alert(meta_keyword_it);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tag" >
<tags-input v-model="tags" id="meta_keyword" >dfg</tags-input>
</div>
Upvotes: 2