Jump to content

Get Element Above Text


chasethemetal
 Share

Recommended Posts

Hey all! I was wondering what the method would be to grab the element above an elements text would be or if its possible? <div id="content1" style="display:none;">Hello World</div><div id="clickme"></div> The reason I need to get the element above's text is I am already getting different information from "clickme"'s child elements... So in other words I can't nest "content1" inside of "clickme" so the whole next() and prev() methods won't work for my application. Thanks so much!

Link to comment
Share on other sites

The reason I have it outside is because I'm using an api that needs the info thats nested and if I have extra info in there it messes it up. But I still need to add some custom info elsewhere on the page on a click function. Now I prefer to use jQuery. I believe I'm onto something with using .parent() some more tweaking and I think I'll have it. Will post my solution, also if someone else has any ideas let me know!

Link to comment
Share on other sites

Maybe not? I don't know. I just starting to get a grip on js and jquery $("div#clickme").click(function () {alert(document.getElementById("clickme").previousSibling);}); this alerts [object Text]... and $("div#clickme").click(function () {alert(document.this.previousSibling);}); alerts nothing.

Edited by chasethemetal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...