Search code examples
jquerycustom-tag

Selecting a non-tag element in jQuery


I have the multiple tags as mentioned below in my HTML. Note the square brackets like BBcode.

[oembed]http://rich-media.url[/oembed]

I need to get the value of URL using jQuery. Any help would be appreciated.


Solution

  • Please have a look at updated fiddle:

    https://jsfiddle.net/hxa4m8Ld/1/

    var content = $('#mytags').text();
    var currIndex = 0;
    while(currIndex < content.length){
        var stIndex = content.indexOf("[oembed]",currIndex);
      var edIndex = content.indexOf("[/oembed]",stIndex);
      if(stIndex > -1 && edIndex> -1){
        var url = content.substring(stIndex+8,edIndex);
        currIndex = edIndex+9;
        console.log(url);
      }
      else
      {
        currIndex = content.length;
      }
    }
    

    I used simple javascript string functions to fetch the required urls. Hope that will help you.