0

This might sound like a question already asked before but actually isn't. I know how to access elements using JQuery but in this situation, the parent element has a colon in its name which is making it difficult. The structure is as follows:

<fb:comments class='fb_iframe_widget'>
   <span>something</span>
</fb:comments>

Note that the span I need to access doesn't have an ID or class and when I use the regular JQuery construct it throws an error due to the colon:

var fbspan = $('fb:comments span');

If colons are not allowed in tag names, how does Facebook do it in the first place? But more importantly, how do I access that span inside <fb:comments>?

2
  • Are you sure that element still exists in the DOM? I believe the FB SDK will change the source you have there in to valid HTML elements. Check the DOM inspector to see what the actual output is. Commented Feb 5, 2016 at 13:48
  • 1
    If colons are not allowed in tag names, how does Facebook do it in the first place?.....that can be achieved with xmlnamespacing. Commented Feb 5, 2016 at 13:49

4 Answers 4

2

you can do it by using class if that solves your problem, like

$(".fb_iframe_widget").find("span");

or

$(".fb_iframe_widget span");
Sign up to request clarification or add additional context in comments.

Comments

1

You need to escape the colon. Currently, jQuery is trying to read "comments" as a pseudo element.

var fbspan = $('fb\\:comments span');

Here's a fiddle.

Comments

1

use the children()' to find span

$("fb\\:comments").children("span")

Comments

1

If you know the index of the occurrence of the span you wish to select will not change, you could use .eq() to select it.

Ex.

$('.fb_iframe_widget').eq(1).css({'color' : 'blue'})

https://jsfiddle.net/w37t1wzg/

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.