2

I insert fields on my page using the JQuery .html() function. The fields have a class attribute, but it seems like the CSS, which is declared in the header part of the page doesn't apply to the element.

I believe it just impact class selector, since I have a #editZone input selector that work like a charm.

Here's a code sample:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<style type="text/css">
    #editZone input, #editZone textarea, #editZone select{
        border:0px;
    }

    #editZone .dependant {
        background-color:#CCC;
        border-bottom:1px solid #333;
    }
    #editZone .original {
        background-color:#FFF;
        border-bottom:1px solid #300;
    }
</style>

</head>
<body>

    <div id="headZone">
        Template:
        <select id="template">
        </select>
        <input type="button" id="generateTpl" value="Go" />
    </div>
    <div id="editZone" style="background-color:#ccc;">content will be filled here upon template selection</div>
    <div id="previewZone">final</div>
</body>
</html>

Here's a content sample (from firebug):

<div style="background-color:#ccc;" id="editZone"><br>
<br>
Name - <input type="" class="original" value="" name="first_name" id="first_name_1"> <input type="" class="original" value="" name="last_name" id="last_name_1"><br>
Title<br>
...
8
  • 3
    Question is about jQuery, but you don't show your jQuery code? Commented Nov 16, 2012 at 21:04
  • 2
    works for me. jsfiddle.net/tomprogramming/yka2w Commented Nov 16, 2012 at 21:08
  • Well considering that the content does populate, I didn't want to polute the question with javascript code that work... Commented Nov 16, 2012 at 21:08
  • 2
    You should use the tools in your browser to examine the effective style rules of your dynamically-added elements. Commented Nov 16, 2012 at 21:10
  • 1
    Chances are your elements aren't being appended where you think they are. (which we could confirm if you provided js code) Commented Nov 16, 2012 at 21:12

2 Answers 2

1

You should close the html tags and I think it should work then. Close the tags like "<tagname />" or "<tagname></tagname>". I mean input, br and all the opened tags are not closed.

Hope it helps.

Cheers

Sign up to request clarification or add additional context in comments.

5 Comments

<input>, <br>, and many other tags do not have to be closed. Self-closing tags are not meaningful in HTML5.
Thank you for mentioning that @Pointy, but I think answer is not flagged as HTML5. Am I right?
It has the HTML5 DOCTYPE at the top :-)
... and I do have closing tag, but the part that you see is the firebug dump that remove them...
Yeah, but maybe the user doesn't now himself that it's the doctype of HTML5. ;)
1

In the style declaration, I had a weird space between the class name and the {.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.