开发者

Using AJAX to request and inject html but what to do to get css applied to injected html?

I'm using jQuery AJAX to request html pages so no refreshes will be needed when someone clicks an menu item. But the things is, I'm currently requesting HTML pages with no doctype, head and body tags.. just only the content (with just h1 tags and tags like that).

The problem is that when I inject that into an div on my main page the css doesn't get applied to the injected content. It does set the text color and makes H1 an heading but it doesn't apply specific things like h1:first-letter. So I'm assuming it only applies general css properties like the text format I applied to the body of the main page.

So the question is how can I make the css apply to the AJAX requested and injected content? Should I include an css file to the file I'm requesting? Should I use some jQuery function to apply it after the injection? Or .. ?

Thanks in advance开发者_如何转开发!


The problem is that when I inject that into an div on my main page the css doesn't get applied to the injected content.

CSS will apply to injected HTML exactly as it does to already existing tags. If it doesn't work, you have a problem in your CSS markup. Can you show a live example?


Can you add a class to your new content?

$('p').addClass('myClass yourClass');

http://api.jquery.com/addClass/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜