Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:13:21+00:00 2026-06-11T14:13:21+00:00

I have a page generated by Yii CListView which contains a div and multiple

  • 0

I have a page generated by Yii CListView which contains a div andmultiple child divs.I need to access a specific the child div and add one more div into that.

Although I managed to solve it using one approach but dont think its the right one. Following is the overview of my solution (the code below does not contain all necessary variables declarations and other stuff, I have pasted the core code not the complete.):

  1. Accessed the parent div by Id (Since the Id was available as I can
    code this into Yii)
  2. Obtained all the elements in this div using :

    var div_childern = document.getElementById('StudentGridViewId').getElementsByTagName('*');
    
  3. Iterated through and when reached to the desired div, added my new div. Please note that the div in which I want to add new div has the class name as “items”. Code as below:

        for (var i = 0; i < div_childern.length; i++) {
        if (div_childern[i].getAttribute('class')=='items'){
            document.getElementById('StudentGridViewId').getElementsByTagName('*')[i].appendChild(newdiv);
            i=div_childern.length+1;
        }
      }
    

The only problem in this solution is, I am accessing the whole document twice, the call to getElementsByTagName. First to obtain the list of all items and then again to add my new div. Is there a better way to this ?

and also, could anyone point me to set the Id of the “items” div that Yii generates?

Thanks
Faisal

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:13:22+00:00Added an answer on June 11, 2026 at 2:13 pm

    You might be able to get a much more elegant solution if you use JQuery.
    But, if you want to use the traditional javascript, here is what you could do

      for (var i = 0; i < div_childern.length; i++) {
        if (div_childern[i].getAttribute('class')=='items'){
            div_childern[i].appendChild(newdiv);
            i=div_childern.length+1;
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wordpress-generated page where I need some posts (in a specific category)
I have a page which contains a dynamically generated grid, where a user can
I have a page which contains the generated content. Page.aspx: <asp:DropDownList ID=cmbUsers runat=server AutoPostBack=True
I have a drop down list which is dynamically generated using ajax on page
I have a page generated by a database. It creates a DIV for each
I have a page in which controls are dynamically generated as the user navigates
I have a page that is generated which inserts an HTML comment near the
If I have a page which gets generated using PHP and then modified using
I have a page in which one chooses from a selection of dynamically generated
I have a trivia page that is dynamically generated by some javascript code. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.