How do I add text to specific div element using jQuery?

后端 未结 5 1166
南笙
南笙 2021-02-14 05:08

I am having a problem with jquery. My HTML is

5条回答
  •  遥遥无期
    2021-02-14 05:47

    You need to use the :first selector to say that you only want to add text to the first element the selector finds. Try this:

    $j('span.test:first').text('Welcome');
    

    Example fiddle

    Alternatively, you can use the id of the parent div to make the selector unique:

    $j('#first .test').text('Welcome');
    

提交回复
热议问题