Taking ownership of an object with jquery and changing its style with css

Asked

Viewed 310 times

0

Problem: I mount a news modal with properties of an object, however, in the title property of the object I need to pass the number of views dynamically, and need to change the source of the number of views. What happens is that when the user hovers over the title, the style I applied appears, IE, HTML code appears for the end user

EXAMPLE

config = {
            title: (data.nmcategoria || 'Geral') + ' | ' + data.dtpublicacao + ' | ' + data.nmtitulo + '<h6 style="line-height:7px;">' + data.nrvisualizacao + ' visualizações' + '</h6>', 
            content: tpl,
            isConfirm: false,
            titleElippsis: true,
            modalHeight: 568,
            modalWidth: 1024,
            justText: true

The idea I had to solve this was to take the title property of the object, and change the styles with jquery and css, something like this:

var pegaObj = $(config).attr('title', 'style',  'line-height:7px;');

but without success, some tip galera?

  • let me get this straight, do you want to change Stylo when the condition changes correctly? I believe this will help you: http://api.jquery.com/css/

  • Every time the user opens the modal, the number of views appears, until then correct. However, as I changed the style in title, every time the cursor goes over the title appears HTML code for the user to see. I’ll take a look at that documentation

1 answer

0

You can use the method css()jQuery bilioteca to apply styles to the desired element.

In this way:

var pegaObj = $(config).css({"line-height":"1", "width":"250px"});

Or if you prefer, you can create a classe specific, define some styles and apply it with addClass() in the desired element.

For more information you can consult the jQuery API at the links below:

Apply CSS with jQuery: http://api.jquery.com/css/

Apply a class to the element with jQuery: https://api.jquery.com/addclass/

You can also try the following:

// Pega o elemento
var pegaObj = $(config);
// Aplicar o estilo ao elemento pego pelo jQuery 
pegaObj.css({"line-height":"1", "width":"250px"})
  • exactly what I was trying to do, but I need to take the class of the div that Modal is, by object property Jquery can not apply the styles, so I’m trying to solve so:

  • $("div[class='modal'] > H4"). css({ "line-height":"7" });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.