0

I am targeting dynamic divs for that I made a code

if ($("#" + selector_name "#" + name + add_count).size() == 0) {
    var p = "<div id = '" + name + add_count + "' class='progressbar' data-perc='0'><div class='bar'><span></span></div><div class='label-up'><span></span></div><div class='mi-avtr-cnt'></div><div class='clear'></div></div>"; 
    $(".mitxt").append(p);  
} 

How can I target divs dynamically . The problem is with line "#" + selector_name "#" + name + add_count

1
  • What are selector_name, name and add_count? You should provide more context! Also, you are missing + between selector_name "#". Commented Nov 16, 2014 at 8:10

2 Answers 2

1

You have a syntax error because a + is missing:

if ($("#" + selector_name + "#" + name + add_count).size() == 0) { ... }
                          ^ -- This was missing

Also note that ids are supposed to be unique in document, so a div can only have one id (that is also unique). You may want to do $("#" + selector_name + ",#" + name + add_count) (selecting two elements with different ids).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for noticing it . :)
0

"#" + selector_name "#" + name + add_count this selector is not a valid selector(And this is a syntax error). A valid id selector is '#' + your_element_id

use '#' + name + add_count as selector should solve your problem

1 Comment

That's not really a selector, that's an error-prone expression.

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.