Referencing DOM element in Jquery in another way

1

Hello, look at these lines of code:

 <div id="divn4" align="center"><i style="">Nunca, nunca enviamos span.</i></div>

So, if I wanted to reference the italic there, to apply some function in it, without having to put an id, or class, in Jquery how can I do it? I think of something like:

$("#divn4[i]").text("teste");

In short, it would be something like in CSS, where you can create a selector not necessarily using an ID or Class.

    
asked by anonymous 22.12.2014 / 01:20

1 answer

3

The i is an HTML tag in the same way as p or div , and therefore a valid CSS selector, so the solution is:

$("#divn4 i").text("teste");

If you want to change all the italics you can even use $("i")

Example:

$("#divn4 i").text('Texto dentro do "i" aqui.');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="divn4" align="center">Texto fora do "i" aqui. <i style="">Nunca, nunca enviamos span.</i></div>
    
22.12.2014 / 01:21