Home > DeveloperSection > Forums > Change attributes of a DOM element when it appears
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    April-05-2013 1:50 AM

 JQuery JQuery 
Ratings:


 2 Reply(s)
 746  View(s)
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!


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    April-05-2013 8:20 AM

Hi Ankit!

Try this way, i hope it solve your problem!

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

Vijay Shukla

Total Post:100

Points:700
Posted on    April-05-2013 8:25 AM

Hi Ankita!

modify your condition as below

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

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


Don't want to miss updates? Please click the below button!

Follow MindStick