最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Add HTML into an existing div with MooTools - Stack Overflow

programmeradmin3浏览0评论

Good Day Folks.

Pardon my experience with MooTools.

To sum up, the CMS generates this code:

<div class="gk_tab gk_tab-style1 clearfix-tabs" id="slideshow-tabs" style="width: 418px; ">
    <ul class="gk_tab_ul-style1">
        <li id="slideshow-tabs_tab_1" class="active"><span>Video</span></li>
        <li id="slideshow-tabs_tab_2" class=""><span>Calendar</span></li>
    </ul>
</div>

I need to able to insert this code when the page finishes loading:

<li id="slideshow-tabs_tab_0" class=""><a><span>Video</span></a></li>

In a particular space. The end result should be:

<div class="gk_tab gk_tab-style1 clearfix-tabs" id="slideshow-tabs" style="width: 418px; ">
    <ul class="gk_tab_ul-style1">
        <li id="slideshow-tabs_tab_0" class=""><a><span>Video</span></a></li>
        <li id="slideshow-tabs_tab_1" class="active"><span>Video</span></li>
        <li id="slideshow-tabs_tab_2" class=""><span>Calendar</span></li>
    </ul>
</div>

So I know I would need to create a new element with the new HTML I want to add and then interject it, but unsure how as efficiently as possible. Oh and yes, I have a specific reasoning for needing to do this, but didn't want to boggle down this post with all the extra info and code. Thanks so much in advance! I'll keep searching on here in the mean time to see if I can figure it out.

PS. The class I'm interjecting it into exists in other parts of the page. So I would have to make sure to specify the id="slideshow-tabs" as well.

Good Day Folks.

Pardon my experience with MooTools.

To sum up, the CMS generates this code:

<div class="gk_tab gk_tab-style1 clearfix-tabs" id="slideshow-tabs" style="width: 418px; ">
    <ul class="gk_tab_ul-style1">
        <li id="slideshow-tabs_tab_1" class="active"><span>Video</span></li>
        <li id="slideshow-tabs_tab_2" class=""><span>Calendar</span></li>
    </ul>
</div>

I need to able to insert this code when the page finishes loading:

<li id="slideshow-tabs_tab_0" class=""><a><span>Video</span></a></li>

In a particular space. The end result should be:

<div class="gk_tab gk_tab-style1 clearfix-tabs" id="slideshow-tabs" style="width: 418px; ">
    <ul class="gk_tab_ul-style1">
        <li id="slideshow-tabs_tab_0" class=""><a><span>Video</span></a></li>
        <li id="slideshow-tabs_tab_1" class="active"><span>Video</span></li>
        <li id="slideshow-tabs_tab_2" class=""><span>Calendar</span></li>
    </ul>
</div>

So I know I would need to create a new element with the new HTML I want to add and then interject it, but unsure how as efficiently as possible. Oh and yes, I have a specific reasoning for needing to do this, but didn't want to boggle down this post with all the extra info and code. Thanks so much in advance! I'll keep searching on here in the mean time to see if I can figure it out.

PS. The class I'm interjecting it into exists in other parts of the page. So I would have to make sure to specify the id="slideshow-tabs" as well.

Share Improve this question edited Mar 8, 2011 at 22:23 TechRemarker asked Mar 8, 2011 at 22:15 TechRemarkerTechRemarker 2,93811 gold badges42 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Using MooTools 1.3:

var li = new Element('li#slideshow-tabs_tab_0'), a = new Element('a'), span = new Element('span', {'text': 'Video'});
span.inject(a);
a.inject(li);
li.inject($$('#slideshow-tabs ul')[0], 'top');
发布评论

评论列表(0)

  1. 暂无评论