简体   繁体   English

使用 jquery 获取对象内的内容

[英]get content inside object using jquery

I am trying to get the HTML content inside object this is what I am trying.我正在尝试获取对象内的 HTML 内容,这就是我正在尝试的。

<div id="description_text">
    With your permission we and our partners would like to use cookies in order to access and 
   record information and process personal data, such as unique identifiers and standard 
  information sent by a device to ensure our website performs as expected, 
</div>

Jquery code查询代码

<script>
   var description_t = $("#description_text").text();
   console.log(description_t);
</script>

in console I am getting the value for Var but when I am trying append in object like below that is not coming在控制台中,我获得了 Var 的值,但是当我尝试追加如下对象时,该值不会出现

 languages: {
        en: {
            consent_modal: {
                title: "",
                description: description_t,
            },
         }
       }

I am not getting any error and my content also not coming what I am doing wrong here can someone please help me我没有收到任何错误,我的内容也没有出现我在这里做错了什么有人可以帮助我

Maybe the problem is that you have not link jQuery file to your home file .ie也许问题是您没有将 jQuery 文件链接到您的主文件 .ie

<script src="jquery-3.5.1.js"></script>
<script>
    var description_t = $("#description_text").text();
    console.log(description_t);
 </script>

Provide the source of jQuery in script tag you will get the right answer在 script 标签中提供 jQuery 的来源你会得到正确的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM