是否可以使定位元素相对于当前不是其父元素的另一个元素?例子:
<div class="want-to-be-parent">
<div class="current-parent">
<div class="element-to-position"><!---content---></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下,我想将“元素到位置”绝对定位在“想要成为父母”的左上角,但它目前相对定位在“当前父母”内。
编辑 - 假设所有这三个元素都具有“位置:相对”并且我无法控制它。我想绝对定位“元素到位置”,并让它相对于“想要成为父母”而不是“当前父母”进行绝对定位。我必须动态执行此操作,因为没有其他方法。
如果通过在span类中包含这些单词而在标题中找到它们,我想强调某些单词.有没有办法编写一个单词列表来检查,然后使用相同的命令用span类包装任何这些单词?
例如:
<h1>This title contains the word Balloon</h1>
<h1>This title contains the word Oranges</h1>
<h1>This title doesn't contain either of those terms</h1>
Run Code Online (Sandbox Code Playgroud)
要检查这三个元素中的每个元素(但是会有20个左右)用于Balloon或Oranges,然后用span颜色包裹这些单词.
我可以用:
$('h1').html($('h1').html().replace(/(balloon)/g,'<span class="red">balloon</span>'));
Run Code Online (Sandbox Code Playgroud)
但是我必须为每个单词写出那个查询,而如果可能的话,我想要一些更简单的东西.
我正在寻找一种方法来搜索div中某个单词中的某个单词,如果找到则用其他内容替换整个句子.
因此,例如,如果div包含"我爸爸烹饪最好的苹果派"的标题,那么我想找到"苹果"这个词,然后用其他东西替换整个句子,例如:"我的爸爸".
我找到了这个,但这只能替换句子中的实际单词,而我想替换整个句子.
$(".div_class").text(function () {
return $(this).text().replace("word", "another word");
});?????
Run Code Online (Sandbox Code Playgroud)
一如既往地非常感谢任何帮助.
有没有办法检查页面上是否存在div元素,如果它确实找到该页面的h1,将其从它所在的位置删除,并将其添加到找到的div元素中?例:
<div id="banner">
<!---find if this div exists first--->
</div>
<div class="page">
<h1>Then find this and add it instead to above banner</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
如果顶部横幅不存在,那么页面将需要保持不变.