[Solved] Adding attributes with jquery


There are a few issues on your snippet.

  1. You are not loading jQuery library so you cannot select a DOM element(such as p.slider-price) like $(“p.slider-price”). To fix that, you should load the jQuery library (in fiddle you do that by choosing it from the frameworks & extensions menu).
    Than, using jQuery you will be able to change the attributes, for example:

$("p.slider-price").attr('data-position', "2");

  1. You have some issues on trying to calculate the attrbt (mainly because you should first understand what this and parent means).
    In your case, you are assuming that parent is the parent DOM element of your p element, but javascript or jQuery doesn’t understand that.
    So, first you select(and/or save) your p element, than you would be able to get its parent and than you could calculate different values.

Combining all what I explained, you will get this fiddle which does what you are expecting:
http://jsfiddle.net/p62qyvax/4/

1

solved Adding attributes with jquery