0

how canI get expr:content value using JavaScript ??!!

<meta expr:content='data:blog.blogId' itemprop='blogId'/>
<meta expr:content='data:post.id' itemprop='postId'/>

i tryed the methode of getElementsByTagName("meta") var x = document.getElementsByTagName("meta"); txt=x.expr:content;

but he give me undefined

1 Answer 1

1

Try using document.querySelectorAll() with selector "meta[expr\\:content]" , for loop , .getAttribute()

var metas = document.querySelectorAll("meta[expr\\:content]");

for (i = 0; i < metas.length; i++) {
  console.log(metas[i].getAttribute("expr:content"))
}
<meta expr:content='data:blog.blogId' itemprop='blogId' />
<meta expr:content='data:post.id' itemprop='postId' />

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

5 Comments

<!DOCTYPE html> <html> <body> <head> <span expr:content='data:blog.blogId' itemprop='blogId'/> <span expr:content='data:post.id' itemprop='postIds'/> </head> <button onclick="myFunction()">Test</button> <script> function myFunction() { var metas = document.querySelectorAll("meta[expr\\:content]"); for (i = 0; i < metas.length; i++) { txt=console.log(metas[i].getAttribute("expr:content")); alert (txt); } } </script> </body> </html> I tried this code but he didn't give me any answer
@AymenLaroussi "tried this code but he didn't give me any answer" No meta elements appear at html at comment stackoverflow.com/questions/34099978/… ? Why are span elements within head of document ? See original Question: "how can I get expr:content value from meta tag using javascript"
just want to have the 'data:blog.blogId' value and 'data:post.id' value using javascript wish variable x = 'data:blog.blogId' value y = 'data:post.id' value using JavaScript to extract them
@AymenLaroussi Try declaring variables outside of for loop , checking i jsfiddle jsfiddle.net/4vcdnmvg ; or filter by itemprop
please give me a favor i'm not pro i'm just beginner in coding please if you want give me the hole solution i'm tired of testing wanna copy past

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.