0

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);
});
Jack Bashford
44.3k11 gold badges56 silver badges84 bronze badges
asked Nov 13, 2018 at 6:44
1
  • 3
    you dont need to convert this in my opinion Commented Nov 13, 2018 at 6:46

2 Answers 2

1

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>
answered Nov 13, 2018 at 6:54
Sign up to request clarification or add additional context in comments.

Comments

1

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)
})
answered Nov 13, 2018 at 7:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.