1

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:

enter image description here

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!!!

3
  • 1
    have you tried .text() - .val() is reserved for form inputs (not sure how that tag is rendered - does it get converted?) Commented Mar 7, 2019 at 12:18
  • good,.text() is the solution,thank you Commented Mar 7, 2019 at 12:21
  • Possible duplicate of When do I use .val() vs .innerHTML? Commented Mar 7, 2019 at 12:35

3 Answers 3

2

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>

Sign up to request clarification or add additional context in comments.

Comments

1

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>

1 Comment

change val() by text() fix the problem,thank you for your help
1

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.

1 Comment

change val() by text() fix the problem,thank you for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.