{"id":4333,"date":"2025-08-09T17:26:20","date_gmt":"2025-08-09T16:26:20","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=4333"},"modified":"2025-08-09T17:26:20","modified_gmt":"2025-08-09T16:26:20","slug":"targeting-specific-elements-within-an-id","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/manipulating-html\/targeting-specific-elements-within-an-id","title":{"rendered":"Targeting specific elements within an ID"},"content":{"rendered":"\n<p>Altering the text within a &lt;p> nested below a &lt;div with the assigned ID=\u201dCreateTokenTokenCost\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"elementor-element elementor-element-9c45b00 elementor-widget elementor-widget-text-editor\" data-id=\"9c45b00\" data-element_type=\"widget\" id=\"CreateTokenTokenCost\" data-widget_type=\"text-editor.default\"&gt;\n  &lt;div class=\"elementor-widget-container\"&gt;\n    &lt;p style=\"text-align: center;\"&gt;$##.##&lt;\/p&gt;\n  &lt;\/div&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>If you use this on the ID:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>document.getElementById('CreateTokenTokenCost').textContent = \"\u00a312.34\";<\/code><\/pre>\n\n\n\n<p>You will remove the &lt;div&gt; and &lt;p&gt; surrounding the target text, resulting in styling being lost. Instead use querySelector to target the &lt;p&gt; directly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>document.querySelector('#CreateTokenTokenCost p').textContent = '$12.34';<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Altering the text within a &lt;p> nested below a &lt;div with the assigned ID=\u201dCreateTokenTokenCost\u201d: If you use this on the ID: You will remove the &lt;div&gt; and &lt;p&gt; surrounding the target text, resulting in styling being lost. Instead use querySelector to target the &lt;p&gt; directly:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-4333","post","type-post","status-publish","format-standard","hentry","category-manipulating-html"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=4333"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4333\/revisions"}],"predecessor-version":[{"id":4334,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4333\/revisions\/4334"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=4333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=4333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=4333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}