{"id":232,"date":"2013-06-15T15:56:36","date_gmt":"2013-06-15T15:56:36","guid":{"rendered":"http:\/\/www.corrspt.com\/blog\/?p=232"},"modified":"2013-06-18T16:57:20","modified_gmt":"2013-06-18T16:57:20","slug":"dealing-with-jsf-ids-in-css-and-javascript-jquery","status":"publish","type":"post","link":"http:\/\/www.corrspt.com\/blog\/2013\/06\/15\/dealing-with-jsf-ids-in-css-and-javascript-jquery\/","title":{"rendered":"Dealing with JSF ids in CSS and Javascript (JQuery)"},"content":{"rendered":"<p>Hi everyone,<\/p>\n<p>If you ever had the opportunity to work with JSF applications (or JSF&#8217;ish applications like XEO Applications) you may have noticed that most elements in the page have these weird ids like <em>form:input<\/em><\/p>\n<p>Imagine the following example in a XEO Application:<\/p>\n<pre class=\"brush:xml\">&lt;xvw:form id='form'&gt;\r\n   &lt;xvw:attribueText id='name' objectAttribute='username'&gt;\r\n&lt;\/xvw:form&gt;<\/pre>\n<p>The resulting HTML would create a div for the input like the following:<\/p>\n<pre class=\"brush:xml\">&lt;div id='form:name'&gt;\r\n ...\r\n&lt;\/div&gt;<\/pre>\n<p>Now, if you want to use Jquery to do something to this element, you would probably do it like this:<\/p>\n<pre class=\"brush:js\">$(\"#form:name\")<\/pre>\n<p>The problem is that you can&#8217;t do this, because in Jquery selectors the colon &#8220;:&#8221; is a special character and cannot be used like this to select an id. In order for the jquery selector to work you have to escape the colon with a double backslash, like the following:<\/p>\n<pre class=\"brush:js\">$(\"#form\\\\:name\")<\/pre>\n<p>But that is one ugly piece of code&#8230; you can do the following to ease the pain:<\/p>\n<pre class=\"brush:applescript\">$(document.getElementById('form:name'))<\/pre>\n<p>Document.getElementById does not interpret selector, as such there&#8217;s no problem having the colon, and since the jQuery selector accepts a DOM element, all is well. If you&#8217;re using the XEO Framework, you can do the following as well:<\/p>\n<pre class=\"brush:js\">$(XVW.get('form:name'))<\/pre>\n<p><strong>And what about CSS?\u00a0<\/strong><\/p>\n<p>Well with CSS the problem is the same, you cannot have the colon in identifiers, so you have to escape it, like the following:<\/p>\n<pre class=\"brush:css\">\/* Wrong *\/\r\n#form:name{\r\n color : red;\r\n}\r\n\r\n\/* Correct *\/\r\n#form\\:name{\r\n color : red;\r\n}<\/pre>\n<p>There&#8217;s just one little problem&#8230; this doesn&#8217;t work in IE6\/7 (shocking, I know). In order to have a compatible solution you need the following:<\/p>\n<pre class=\"brush:css\">\/* Correct! Compatible with IE 6\/7 *\/\r\n#form\\3A name{\r\n  color : red;\r\n}<\/pre>\n<p>And I think this pretty much nails it \ud83d\ude42 Hope it helps someone!<br \/>\nHappy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi everyone, If you ever had the opportunity to work with JSF applications (or JSF&#8217;ish applications like XEO Applications) you may have noticed that most elements in the page have these weird ids like form:input Imagine the following example in &hellip; <a href=\"http:\/\/www.corrspt.com\/blog\/2013\/06\/15\/dealing-with-jsf-ids-in-css-and-javascript-jquery\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[22,19,20,21],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-web-development","tag-css","tag-javascript","tag-jquery","tag-jsf"],"_links":{"self":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":5,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":249,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/posts\/232\/revisions\/249"}],"wp:attachment":[{"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.corrspt.com\/blog\/wp-json\/wp\/v2\/tags?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}