I have never used javascript before, but I know most other programming languages.

<div id="test">
  <p class="location">New Jersey</p>
</div>

Is there a way to take out "New Jersey" and save it in a variable using javascript and then to remove the <div> who contains the class="location" (its parent?)

var theDiv = document.getElementById("test");
//the div's content
alert( theDiv.innerHTML );

/* get the paragraph - NOTE: getElementsByTagName returns an array of references to the elements that match the tag specified. In this case "p". Arrays are zero indexed, so the first P element is at index zero. If you had more than one P within the div, then the second P would be at index 1, etc. */
var theP=theDiv.getElementsByTagName("p")[0];

//the content of the paragraph
alert( theP.innerHTML );

//removing the theDiv from the page
theDiv.parentNode.removeChild( theDiv );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.