CHANGE ATTRIBUTES OF A DOM ELEMENT WHEN IT APPEARS

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
JQuery 
 970  View(s)
Ratings:
Rate this:
Hi All!

Is there a way to change the attribute of a DOM element as it is created? I have an input (has an ID) that is created by a plugin. I need to change the 

placeholder of that input when it appears.

i.e.

$("#token-input_sample").live("attr","placeholder","place");
Code above doesn't work.

Thanks in advance!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Change attributes of a DOM element when it appears

    Hi Ankit!

    Try this way, i hope it solve your problem!

    $('#token-input_sample').prop('placeholder', 'place');

  1. Vijay Shukla

    Post:100

    Points:700
    Re: Change attributes of a DOM element when it appears

    Hi Ankita!

    modify your condition as below

    var $input = $('#token-input_sample');

    if($input.length > 0)
       $input.prop('placeholder', 'place');

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!