Reputation: 683
I've modified this answer and got it working. However, I want to improve it by translating this JQuery code for uniformity since I'm working with a team. Can I somehow convert the code to JQuery?
Javascript Code
var o = document.querySelector("#divTwo");
var gg = o.querySelector('#tempType [aria-selected="true"]').innerText;
o.querySelectorAll('[templateList="me"] .entry-footer [template-include = "true"]').forEach( (elm) => {
var a = elm.closest( '.popup-temp-entry' ).querySelector( '.entry-header' ).innerText;
var b = elm.closest( '.popup-temp-entry' ).querySelector( '.entry-body' ).innerText;
console.log(a +' - '+ b + ' - ' + gg);
});
Upvotes: 0
Views: 217
Reputation: 81
you could also try this one.
var o = $("#divTwo"),
gg = o.find("#tempType [aria-selected='true']").text()
o.find("[templateList='me'] .entry-footer [template-include='true']").forEach( (elm) => {
var foo = elm.closest( '.popup-temp-entry' ),
a = foo.find(".entry-header").text(),
b = foo.find("entry-body").text()
console.log(gg, a, b)
})
Upvotes: 1
Reputation: 44087
If you really want to convert that JavaScript to jQuery, just do this:
var o = $("#divTwo);
var gg = o.filter("#tempType [aria-selected='true']").text();
o.filter("[templateList='me'] .entry-footer [template-include = 'true']").each((elm) => {
var a = elm.next(".popup-temp-entry").filter(".entry-header").val();
var b = elm.next(".popup-temp-entry").filter(".entry-body").val();
console.log(`${a} - ${b} - gg`);
})
Just make sure you have included jQuery correctly:
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
Upvotes: 1