0

I'm using JSF 2.0 and JQUERY 1.9. I'm trying to add an attribute to a component, but when the page is rendered, the attribute is not added.

Here is the jsf code for the component.

  <h:form id="mainForm">
        <h:inputText id="field" value="#{bean.value}"/>
    </h:form>

and the jquery is like this:

<script type="text/javascript">
// <![CDATA[
    window.onload=function(){
        $("#mainForm:field").attr("placeholder","Fill me");
    }
// <![CDATA[
</script>

This is being rendered like this:

<input id="mainForm:field" name="mainForm:field" type="text" value="">

Any idea on where am I wrong? Thanks!

2 Answers 2

2

You should escape the colon in the selector

$("#mainForm\\:field").attr("placeholder","Fill me");
Sign up to request clarification or add additional context in comments.

Comments

1

From the docs:

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\.

Change your selector to $("#mainForm\\:field").

1 Comment

Worked like a charm! Thanks, Blaze!

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.