user3326265
user3326265

Reputation: 257

Number of the element is not working properly

I am creating path elements and adding to a group. Here i don't want to create and add path with same id to the group. so i am skipping the creation and addition of path if 'id' is before used as below

drawPath: function (options, groupElement) {
        if ($("#" + options.id).length > 0) { 
          break;
        }
        else {
            var path = document.createElementNS(this.svgLink, "path");
            $(path).attr(options).appendTo(element);
        }

    },


here the options is the attribute to be set for the path and element is the group element to which the path is added  



options = {
                'id': '23+',
                'd': 'M 0 2 L 3 5'
            };

the options is varying for each path.

when id is '23+' or '23 Above', $("#" + options.id).length is always showing 0, even when the 2nd path id is '23+'. But i don't want to add more than one path with same id.

I am getting this problem only when the id is having special character and white space.

Where i am doing wrong

Thanks in advance

Upvotes: 2

Views: 40

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

This #23+ will not get parsed as a jquery selector, since + is a meta-character. you have to escape that + symbol in order to make it as a valid selector.

Try to change your json like,

options = {
           'id': '23\\+',
           'd': 'M 0 2 L 3 5'
          };

please read here to know about the meta-characters in jquery and how can we use that as a selector.

Upvotes: 3

Related Questions