I'm trying to retrieve a value from a Javascript that does not have a subclass. In this case, I am trying to retreive the "Today" value:
<div class="jobsearch-JobMetadataFooter">
<div>Today</div>
Can it be done? If so, how?
CodePudding user response:
You can use selector: .jobsearch-JobMetadataFooter>div
console.log($(".jobsearch-JobMetadataFooter>div").first().text());
console.log(document.querySelector(".jobsearch-JobMetadataFooter>div").innerText);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="jobsearch-JobMetadataFooter">
<div>Today</div>
</div>
Updated: use 2 ways by jQuery and javascript.
CodePudding user response:
You can grab the text inside the child div like this.
var parent = Document.getElementsByClassName("jobsearch-JobMetadataFooter")[0];
var child = parent.childNodes;
var text = child[1].innerHTML;
Edit: Juan is absolutely right. I had the child index wrong previously.