Results 1 to 3 of 3

Thread: Dynamic Ajax Content with div class instead of id

  1. #1
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content with div class instead of id

    1) Script Title: Dynamic Ajax Content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    3) Describe problem: Is it possible to alter the script so it points to a div class instead of an id?

    thanks

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not sure why you would want to do this. Are you trying to fill multiple divisions on the same page with the same content simultaneously? Or, is it that you just prefer class to id? Either way, you could change this:

    Code:
    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
    }
    to:

    Code:
    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
    var theDivs=document.getElementsByTagName('div');
    for (var i_tem = 0; i_tem < theDivs.length; i_tem++)
    if (theDivs[i_tem].className==containerid)
    theDivs[i_tem].innerHTML=page_request.responseText
    }
    }
    Now class will work like id used to for this script (id will no longer work). I wrote the above for divisions only but, it could be written for other elements or, for all elements that support the class attribute.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot John!

    I do want to fill multiple divisions, as I want to use it to show entries of my CMS(Expression Engine).
    Otherwise it would fill the page with div id's, and that is not what id's stand for, do they.

    I had already found a workaround by setting the entry limit to "1", but this is even better!

    thanks again...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •