function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cmoylecmoyle 

JQuery with visualforce component

So I have an <apex:inputText id="email"> tag in one of my visualforce pages. I'm trying to access it from one of my jquery functions to do some styling on it when the document loads. However, for some reason none of the styling is applied from the jquery function. I'm doing the following:

 

<script>

$(document).ready(function(){

...

var value = $("#emailComponent").val();

$("#" + value).style...

...

});

</script>

...

<apex:inputText id="email"/>

<input type="hidden" value="{!$Component.email}" id="emailComponent"/>

 

If I change the apex tag to a standard html input field, the jquery works. Can someone help me figure out why my jquery styling isn't applied to the apex tag?

Best Answer chosen by Admin (Salesforce Developers) 
cmoylecmoyle

I considered that, but it was going to require too many changes. However I solved my issue by finding out that you have to escape the colons ':' after passing the id into a jquery function. Issue solved :)

All Answers

MarkWaddleMarkWaddle

Instead of using your hidden input, I would recommend giving the inputText a unique CSS class. That way you can just use the jquery class selector directly.

 

For example:

 

<script>
$(document).ready(function(){
...
$(".emailComponentClass").style...
...
});
</script>
...
<apex:inputText id="email" class="emailComponentClass" />

 

 

 

Regards,

Mark

cmoylecmoyle

I considered that, but it was going to require too many changes. However I solved my issue by finding out that you have to escape the colons ':' after passing the id into a jquery function. Issue solved :)

This was selected as the best answer
Chamil MadusankaChamil Madusanka

can you put some clear example for apex tag selectors?

SK R.ax1448SK R.ax1448

Hi,

 

I'm facing something similar issue, could you please share the solution. 

 

 

Thanks a ton inadvance !