Kim Santos
Kim Santos

Reputation: 93

Get the <meta> content and assign it to a div jQuery

I have this <meta content='Stunning Fashion Photoshoot Project' name='description'/> on my page and I would like to assign it's content on <div class="description"></div>. How can I achieve this?

Upvotes: 1

Views: 37

Answers (1)

Always Helping
Always Helping

Reputation: 14570

Just use .attr to get the value and and assign the meta content to your div using .html

Read more about .html here and .attr here

Edit: to Just get the meta where name is description just use this meta[name="description"

Run snippet below to see it working.

//Get Meta
var getContent = $('meta[name="description"]').attr('content');

//Assign to DIV
$('.description').html(getContent)

//Assign to DIV
console.log(getContent)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<meta content='Stunning Fashion Photoshoot Project' name='description' />

<div class="description"></div>

Upvotes: 2

Related Questions