Jump to content

add class to obj


mehdi_php

Recommended Posts

i have a problem . when i select an item it's load with ajax i have div object with an Id attribute inside it . the id is retrieved from database an in foreach loop i iterate this div .

{section name=all loop=$article }
<div id="{$article[all].xarticleid}" style="cursor:pointer" onclick="get_article_body(this);" class="">
{/section}

 

ok . after i click the item it's fetch the article body from db an show it in another div . it's works . i want to change the div inside text each time it's select so i do that .

 

// Function that starts the Ajax process:
function get_article_body(obj) {

obj.addClass('Ared');

if (ajax) {

// Call the PHP script.
// Use the GET method.
// Pass the zip code in the URL.
ajax.open('get', '../ajax/get_article_body.php?id=' + encodeURIComponent(obj.id));

// Function that handles the response:
ajax.onreadystatechange = handle_stores;

// Send the request:
ajax.send(null);

return false;

} else { // Can't use Ajax!
return true;
}

} // End of get_stores() function.

// Function that handles the response from the PHP script:
function handle_stores() {

document.getElementById('desc').innerHTML = '<div align="right"><img src="../images/loading.gif">  Loading Content ...</div>';
// If everything's OK:
if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

// Check the length of the response:
if (ajax.responseText.length > 10) {

// Send the response, in object form,
// to the show_stores() function:
show_stores(eval('(' + ajax.responseText + ')'));

} else {
document.getElementById('desc').innerHTML = 'Loading Content ...<img src="loading.gif">';
}

}

} // End of handle_stores() function.

// Function that shows the list of stores:
function show_stores(stores) {

// Initialize a string:
var message = '';

// Get each store:
for (var i = 0 ; i < stores.length ; i++) {

// Add to the string:
message +=
'<p>' + stores[i].articlebody + '<br />'

}

// Place the string in the page:
document.getElementById('desc').innerHTML = message;

} // End of show_stores() function.

but i got an error . and when i get rid of that line (obj.addClass('Ared')) it's works fine again .

Link to comment
https://forums.phpfreaks.com/topic/134336-add-class-to-obj/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.