如何通过使用css / js向页面添加内容?

时间:2013-08-26 23:22:45

标签: javascript css wordpress

我正在开发一个房地产网站。该网站正在使用付费服务,允许人们通过我的网站查看房地产列表。我的网站成为其他网站的子域名,如www.mywebsite.listingswebsite.com。列表网站动态地在我提供的其中一个页面上提取页眉和页脚包装,并将其内容放在页面中间。所以它看起来像这样。

My Header
Their listings content that I have no control over
My Footer

问题是,我想修改他们的页面。我想在他们的内容之前添加一些内容,我想移动元素,我想删除一些元素。目前,我所知道的是如何从页面中删除元素 - 这是通过查找Div的ID,并在我的CSS文件中添加display:none。

但是如果我想在页面中添加内容呢?我只能控制CSS / JS,所以我该怎么做?说我想在他们的内容之前添加一张图片。

3 个答案:

答案 0 :(得分:0)

Jquery可以成为您最好的朋友,http://jquery.com,只需定位您想要的ID并且:

// Waits until the dom is ready
$(document).ready(function(){
  $("#mytarget").html("this replaces all content in the target");
  $("#mytarget").append("this places your content after content in the target");
  $("#mytarget").prepend("this places your content before content in the target");
});

// Waits until everything is loaded
$(window).load(function(){
  $("#mytarget").html("this replaces all content in the target");
  $("#mytarget").append("this places your content after content in the target");
  $("#mytarget").prepend("this places your content before content in the target");
});

答案 1 :(得分:0)

关于jQuery关于DOM Insertion的文档,关于Css,它们包含了操作DOM元素所需的所有内容。

答案 2 :(得分:0)

如果您使用Jquery,则可以使用appendpreprend,“之后”或“之前”方法添加一些内容。希望这会对你有所帮助。

(对不起,我只能发布2个链接,但如果你想要一些例子,你可以轻松找到它们;))