如何使用Jquery重定位此标记?

时间:2011-06-11 09:59:05

标签: jquery wordpress

我想知道我是否可以得到你对Jquery的帮助。注意,我无法修改此代码中的任何html,因为它是在wordpress中使用单独的小部件动态生成的。

我在标签云中有一个标签,类名为“tag-link-169”

<a style="font-size: 1.3em; color: rgb(30, 37, 130);" title="1 topic" class="tag-link-169" href="http://blahblahblah.com/tag/poll-2/">poll</a>

它的父类是<div class="tagcloud">

我想将特定标记“tag-link-169”从标记云中删除并将其放在搜索框之前,该搜索框具有“search_form”类,并且还可以添加html文本标签前面,“点击此标签查看民意调查”

<form action="http://blahblah.com/" class="search_form" method="get">
    <p>
        <input type="text" onblur="if (this.value == '') {this.value = 'To search, type and hit enter';}" onfocus="if (this.value == 'To search, type and hit enter') {this.value = '';}" id="s" name="s" value="To search, type and hit enter" class="text_input">
        <input type="hidden" value="Search" id="searchsubmit">
    </p>
</form>

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:3)

您需要选择元素,然后使用insertBefore将其放在正确的位置。然后,您可以使用before插入文本:

$('a.tag-link-169').insertBefore('form.search_form').before('click this tag to see Polls');

答案 1 :(得分:1)

试试这个:

$('a.tag-link-169').insertBefore('.search_form').before('click this tag to see Polls');

答案 2 :(得分:1)

use .find( classname ) select DOM particular tag having classname.
<div class="parenttoform"
<form action="http://blahblah.com/" class="search_form" method="get">
<p>
<input type="text" onblur="if (this.value == '') {this.value = 'To search, type and hit enter';}" onfocus="if (this.value == 'To search, type and hit enter') {this.value = '';}" id="s" name="s" value="To search, type and hit enter" class="text_input">
    <input type="hidden" value="Search" id="searchsubmit">
</p>
</form>
</div>
// jquery
$('.parenttoform') .append('');
// here what to append, need html right?
//either you can create new html or give parrent div to link like below
<div class="tag-link-169"><a style="font-size: 1.3em; color: rgb(30, 37, 130);" title="1 topic"  href="http://blahblahblah.com/tag/poll-2/">poll</a></div>
now on tag click,
add first and then remove
//jquery

 $('.parenttoform') .append($('.tag-link-169').html());
 $('.tag-link-169').html('');