I have the following code, which is written in DOM API instead of jquery. I'm not sure why. It's inside the submit function for jquery form validation. I need to change the "parentNode" part so that instead of "parent" it is "closest." I'm no good with javascript. I tried my hand at converting this to jquery, but wasn't able to get that to work. Basically, if this were jquery, I'd need to change .parent() to .closest().
var summary = "";
$.each(element, function() {
summary += "<li>" + this.element.parentNode.getElementsByTagName('label')[0].innerHTML.replace("\<span\>*\<\/span\>","") + "</li>";
});
summary = summary.replace(/\<li\>.+\<\/li\>\1/, "$1");
alert(summary);
Is this possible to do with javascript? Or, is there an easy way to convert this to jquery?
UPDATE: Here is a fiddle to help explain what I'm trying to accomplish. Basically, because I added a 'span' tag around one of the inputs, the 'p' tag is no longer the parent. As such, the parentNode is not finding the 'p' tag anymore.
http://jsfiddle.net/9um8xt79/1/
UPDATE 2 -- THE previous fiddle link was incorrect. The link above is the right one.
How can I modify to find the <p>
tag regardless of whether it is the direct parent, or a grandparent?