I would like to "hide" everything encompassed in a particular <p> tag that is 'named' by a variable(created a php script that reads from the db and echo's a users details in a <p> that has the name of the 'member number' via a variable - user. (yes it sounds a bit weird....not easy to explain)

echo "<p id=\"results\" name=\"".$info['username']."\">";
....
echo "</p>";

The above works just fine. The elements name is infact the 'username'. I have passed the variable back to html document as 'user' (yes, I verified that it is the correct value in the variable as it is passed to another php script via ajax and returns the appropriate result)

What I need to do is when I click a button, the contents within the specific <p></p> are set to display:none . The problem I am having is that the elements 'name' is only known by a variable - 'user'. ....I hate coding DOM related functions lol...

Use the 'id' of the element to do the same.

var s = document.getElementById('results').style;
var b = document.getElementById('buttonId');
if(!s || !b)
   return;
b.onclick = function() {
   s.display = 'none';
};

I just changed things a couple hours ago and echo'd a div with the 'username' as the id before the <p> element, then referenced that id in the onreadystatechange of an ajax function(calls an update to the database when a button is clicked) to set it to hidden once the update is complete.

function confirmuser(user) {
	htmlRequest = ajaxFunction();
	var params = "user="+user;
	var getid = document.getElementById(user);
	if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
		alert ("Browser does not support HTTP Request");
		return;
	} 
	htmlRequest.open('POST', 'confirmuser.php');
	htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	htmlRequest.setRequestHeader("Content-length", params.length);
	htmlRequest.setRequestHeader("Connection", "close");
	htmlRequest.onreadystatechange = function() {//Call a function when the state changes.
	if(htmlRequest.readyState == 4 && htmlRequest.Status == 200) {
		getid.style.display = 'none';
		}
	}
	htmlRequest.send(params); 
}

Thanks though :)

This question has already been answered. Start a new discussion instead.