/    Sign up×
Community /Pin to ProfileBookmark

convert id to class

Hi All!

Can someone help me convert the javascript to get the CLASS and [U]not[/U] the ID from a div?

for example:

when the link below is clicked it fills in the div below it with the url requested…

[CODE]
<a href=”javascript:details(‘includes/iframe.php?id=1’, ‘tog16’);” onclick=”toggle(‘tog16’);”>[+]</a>

<div id=”tog16″ class=”tog16″> Blah blah blah </div>
[/CODE]

the problem is that i have the div id being used by a different javascript function, so i need to use the div class for this function below…

[CODE]
function toggle( targetId ){
if (document.getElementById){
target = document.getElementById( targetId );
if (target.style.display == “none”){
target.style.display = “”;
} else {
target.style.display = “none”;
}
}
}

/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var loadedobjects=””
var rootdomain=”http://”+window.location.hostname

function details(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject(“Msxml2.XMLHTTP”)
}
catch (e){
try{
page_request = new ActiveXObject(“Microsoft.XMLHTTP”)
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open(‘POST’, url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf(“http”)==-5))
document.getElementById(containerid).innerHTML=page_request.responseText
}
[/CODE]

Thanks in advance!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JPnycFeb 22.2007 — var divObj=document.getElementsByTagName('div');

var divs='';

for(var i=0;i<divObj.length;i++){

if(divObj[i].classname=='whateverClass') {

//do something to them here

}

}



The DOM method is getAttribute() for this kind of thing but IE doesn't support it with classname, for some reason that only they know. I believe the above works crossbrowser, however.
Copy linkTweet thisAlerts:
@UltimaterFeb 22.2007 — .class[color=blue]N[/color]ame
×

Success!

Help @dlf1987 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...