Selector Tag for getting text value inside anchor tag












0















I need to select only text inside anchor tag ,
div.alphabetical-kategorie-entry a text --- doesn't works
div.alphabetical-kategorie-entry a --- selects along with span element



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a href="https://www.maceus.com/Agricultural-machinery/ci-4" class="">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>









share|improve this question























  • document.querySelectorAll(".alphabetical-kategorie-entry a").forEach(items=>console.log(items.innerHTML)) selects along with span tag

    – Sanjay A
    Nov 21 '18 at 4:36






  • 1





    I'd suggest editing your question and adding the comment and the JavaScript tag, also if you could try to reword your question to make it clear what it is that you are trying to achieve.

    – Madison Courto
    Nov 21 '18 at 4:40
















0















I need to select only text inside anchor tag ,
div.alphabetical-kategorie-entry a text --- doesn't works
div.alphabetical-kategorie-entry a --- selects along with span element



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a href="https://www.maceus.com/Agricultural-machinery/ci-4" class="">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>









share|improve this question























  • document.querySelectorAll(".alphabetical-kategorie-entry a").forEach(items=>console.log(items.innerHTML)) selects along with span tag

    – Sanjay A
    Nov 21 '18 at 4:36






  • 1





    I'd suggest editing your question and adding the comment and the JavaScript tag, also if you could try to reword your question to make it clear what it is that you are trying to achieve.

    – Madison Courto
    Nov 21 '18 at 4:40














0












0








0








I need to select only text inside anchor tag ,
div.alphabetical-kategorie-entry a text --- doesn't works
div.alphabetical-kategorie-entry a --- selects along with span element



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a href="https://www.maceus.com/Agricultural-machinery/ci-4" class="">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>









share|improve this question














I need to select only text inside anchor tag ,
div.alphabetical-kategorie-entry a text --- doesn't works
div.alphabetical-kategorie-entry a --- selects along with span element



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a href="https://www.maceus.com/Agricultural-machinery/ci-4" class="">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>






html css-selectors






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 4:36









Sanjay ASanjay A

12113




12113













  • document.querySelectorAll(".alphabetical-kategorie-entry a").forEach(items=>console.log(items.innerHTML)) selects along with span tag

    – Sanjay A
    Nov 21 '18 at 4:36






  • 1





    I'd suggest editing your question and adding the comment and the JavaScript tag, also if you could try to reword your question to make it clear what it is that you are trying to achieve.

    – Madison Courto
    Nov 21 '18 at 4:40



















  • document.querySelectorAll(".alphabetical-kategorie-entry a").forEach(items=>console.log(items.innerHTML)) selects along with span tag

    – Sanjay A
    Nov 21 '18 at 4:36






  • 1





    I'd suggest editing your question and adding the comment and the JavaScript tag, also if you could try to reword your question to make it clear what it is that you are trying to achieve.

    – Madison Courto
    Nov 21 '18 at 4:40

















document.querySelectorAll(".alphabetical-kategorie-entry a").forEach(items=>console.log(items.innerHTML)) selects along with span tag

– Sanjay A
Nov 21 '18 at 4:36





document.querySelectorAll(".alphabetical-kategorie-entry a").forEach(items=>console.log(items.innerHTML)) selects along with span tag

– Sanjay A
Nov 21 '18 at 4:36




1




1





I'd suggest editing your question and adding the comment and the JavaScript tag, also if you could try to reword your question to make it clear what it is that you are trying to achieve.

– Madison Courto
Nov 21 '18 at 4:40





I'd suggest editing your question and adding the comment and the JavaScript tag, also if you could try to reword your question to make it clear what it is that you are trying to achieve.

– Madison Courto
Nov 21 '18 at 4:40












1 Answer
1






active

oldest

votes


















1














I'm not certain what it is that you are trying to do, but given your comment references JavaScript I'll assume it's something like this;



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a class="" href="https://www.maceus.com/Agricultural-machinery/ci-4">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>


You'll need to give the anchor an Id.



Then access the text content using JavaScript as follows;



var x = document.querySelector("body > div > h2 > a").childNodes[0].textContent;
console.log(x);





share|improve this answer


























  • This gives: Agricultural machinery 348

    – Sanjay A
    Nov 21 '18 at 5:22











  • I am looking to extract only Agricultural machinery not the text in span tag

    – Sanjay A
    Nov 21 '18 at 5:23











  • Can we we do that without changing the structure

    – Sanjay A
    Nov 21 '18 at 5:24











  • Sorry, please see my update

    – Madison Courto
    Nov 21 '18 at 5:32











  • Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

    – Sanjay A
    Nov 21 '18 at 5:50













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405332%2fselector-tag-for-getting-text-value-inside-anchor-tag%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I'm not certain what it is that you are trying to do, but given your comment references JavaScript I'll assume it's something like this;



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a class="" href="https://www.maceus.com/Agricultural-machinery/ci-4">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>


You'll need to give the anchor an Id.



Then access the text content using JavaScript as follows;



var x = document.querySelector("body > div > h2 > a").childNodes[0].textContent;
console.log(x);





share|improve this answer


























  • This gives: Agricultural machinery 348

    – Sanjay A
    Nov 21 '18 at 5:22











  • I am looking to extract only Agricultural machinery not the text in span tag

    – Sanjay A
    Nov 21 '18 at 5:23











  • Can we we do that without changing the structure

    – Sanjay A
    Nov 21 '18 at 5:24











  • Sorry, please see my update

    – Madison Courto
    Nov 21 '18 at 5:32











  • Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

    – Sanjay A
    Nov 21 '18 at 5:50


















1














I'm not certain what it is that you are trying to do, but given your comment references JavaScript I'll assume it's something like this;



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a class="" href="https://www.maceus.com/Agricultural-machinery/ci-4">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>


You'll need to give the anchor an Id.



Then access the text content using JavaScript as follows;



var x = document.querySelector("body > div > h2 > a").childNodes[0].textContent;
console.log(x);





share|improve this answer


























  • This gives: Agricultural machinery 348

    – Sanjay A
    Nov 21 '18 at 5:22











  • I am looking to extract only Agricultural machinery not the text in span tag

    – Sanjay A
    Nov 21 '18 at 5:23











  • Can we we do that without changing the structure

    – Sanjay A
    Nov 21 '18 at 5:24











  • Sorry, please see my update

    – Madison Courto
    Nov 21 '18 at 5:32











  • Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

    – Sanjay A
    Nov 21 '18 at 5:50
















1












1








1







I'm not certain what it is that you are trying to do, but given your comment references JavaScript I'll assume it's something like this;



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a class="" href="https://www.maceus.com/Agricultural-machinery/ci-4">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>


You'll need to give the anchor an Id.



Then access the text content using JavaScript as follows;



var x = document.querySelector("body > div > h2 > a").childNodes[0].textContent;
console.log(x);





share|improve this answer















I'm not certain what it is that you are trying to do, but given your comment references JavaScript I'll assume it's something like this;



<div class="alphabetical-kategorie-entry">
<h2 class="">
<a class="" href="https://www.maceus.com/Agricultural-machinery/ci-4">
Agricultural machinery
<span class="">348</span>
</a>
</h2>
</div>


You'll need to give the anchor an Id.



Then access the text content using JavaScript as follows;



var x = document.querySelector("body > div > h2 > a").childNodes[0].textContent;
console.log(x);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 5:32

























answered Nov 21 '18 at 4:54









Madison CourtoMadison Courto

439312




439312













  • This gives: Agricultural machinery 348

    – Sanjay A
    Nov 21 '18 at 5:22











  • I am looking to extract only Agricultural machinery not the text in span tag

    – Sanjay A
    Nov 21 '18 at 5:23











  • Can we we do that without changing the structure

    – Sanjay A
    Nov 21 '18 at 5:24











  • Sorry, please see my update

    – Madison Courto
    Nov 21 '18 at 5:32











  • Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

    – Sanjay A
    Nov 21 '18 at 5:50





















  • This gives: Agricultural machinery 348

    – Sanjay A
    Nov 21 '18 at 5:22











  • I am looking to extract only Agricultural machinery not the text in span tag

    – Sanjay A
    Nov 21 '18 at 5:23











  • Can we we do that without changing the structure

    – Sanjay A
    Nov 21 '18 at 5:24











  • Sorry, please see my update

    – Madison Courto
    Nov 21 '18 at 5:32











  • Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

    – Sanjay A
    Nov 21 '18 at 5:50



















This gives: Agricultural machinery 348

– Sanjay A
Nov 21 '18 at 5:22





This gives: Agricultural machinery 348

– Sanjay A
Nov 21 '18 at 5:22













I am looking to extract only Agricultural machinery not the text in span tag

– Sanjay A
Nov 21 '18 at 5:23





I am looking to extract only Agricultural machinery not the text in span tag

– Sanjay A
Nov 21 '18 at 5:23













Can we we do that without changing the structure

– Sanjay A
Nov 21 '18 at 5:24





Can we we do that without changing the structure

– Sanjay A
Nov 21 '18 at 5:24













Sorry, please see my update

– Madison Courto
Nov 21 '18 at 5:32





Sorry, please see my update

– Madison Courto
Nov 21 '18 at 5:32













Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

– Sanjay A
Nov 21 '18 at 5:50







Can we get same thing using css Selector like div.alphabetical-kategorie-entry a this gives text along with span element

– Sanjay A
Nov 21 '18 at 5:50






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405332%2fselector-tag-for-getting-text-value-inside-anchor-tag%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?