3

I read this post Handling a colon in an element ID in a CSS selector which outlines how to select a known id that contains a colon.

What I would like to do is create a JSF list that contains images. Then using jQuery I would like to select each image and read in the id. Is this possible without writing some code to replace the colons?

Community
  • 1
  • 1
rsideb
  • 839
  • 10
  • 18
  • I don't understand what you mean with the last question. What is stopping you from doing so? The answer is basically already in the linked question. Just escape the colons using \. What is after all the functional requirement? Are you using JSF 1.x or 2.x? There may be fullworthy JSF solutions. In case of JSF it's more recommended to use a ajaxical JSF component library instead of fiddling low level with jQuery. – BalusC Nov 15 '10 at 21:37
  • I am using JSF 1.2 and a library that was written using jQuery that needs me to pass in the id of an image. The requirement is to put a list of images on a page that each have a unique id. Then pass the ids of those images into a JavaScript function (that uses jQuery). – rsideb Nov 15 '10 at 21:47
  • Do you mean `
    ?`
    – PleaseStand Nov 15 '10 at 21:51
  • Yes that is the output that I would want. – rsideb Nov 15 '10 at 21:57
  • What plugin are you talking about? Is it really so bad designed that it only accepts element ID's and not jQuery elements? – BalusC Nov 15 '10 at 22:44

2 Answers2

5

Use jQuery to iterate over each individual img element. Assuming that your ul element has the id wx:yz:

// Use jQuery to select all images within
var imgs = $('#wx\\:yz img');

// Iterate over each one and give the image ID to the library
// only if the image actually has an ID.
imgs.each(function() {
    if(this.id && this.id.length) {
        nameOfYourLibraryFunction(this.id);
    }
});
PleaseStand
  • 31,641
  • 6
  • 68
  • 95
1

It's safer to use classes instead of IDs when using JSF.

Damo
  • 11,410
  • 5
  • 57
  • 74
  • This is what I am doing right now, but I know that this will not work for some of the issues that I am dealing with. For example, I have some JavaScript Libraries that require me to pass in the id of an element. – rsideb Nov 15 '10 at 21:48