jquery css styling not being applied when appending to the dom

已查看 53 次
跳至第一个未读帖子

fugee ohu

未读,
2019年12月24日 21:07:322019/12/24
收件人 Ruby on Rails: Talk
$('#message_holder').append('<div class="container"><span class="right">' + data.content + '</span><br></div>')

The string gets appended to the message_holder div like so:
<div class="container"><span class="right">9</span><br></div>

but the styling defined in .right doesn't get applied What to do?

Sampson Crowley

未读,
2019年12月30日 16:52:462019/12/30
收件人 Ruby on Rails: Talk
there are a massive number of possible reasons. you really should do some research on css display types, as I'm assuming `right` is supposed to be a element with "float: right" but "span" tags don't respond to floats unless they have been set as block-level elements
已删除帖子

fugee ohu

未读,
2019年12月31日 21:55:462019/12/31
收件人 Ruby on Rails: Talk
view:
<h3>Conversation with <%= @conversation_with.name %></h3>
<%= content_tag :div, id: "message_holder", data: {conversation_with_id: @conversation_with.id} do %>

   <% @messages.each do |m| %>
        <% if m.sender==@conversation_with.id %>
            <div class="container-left"><%= m.content %></div>
        <% else %>
            <div class="container-right"><%= m.content %></div>
        <% end %>
    <% end %>

<% end %>

js:

 received(data) {
   
            if (data.sender==$('#message_holder').data-conversation_with_id)
               {
               $('#message_holder').append('<div class="container-left">' + data.content +  '</div>');
               }
            else
               {
               $('#message_holder').append('<div class="container-right">' + data.content + 'converation_with_id:'  +  '</div>');
               }

  }
});

fugee ohu

未读,
2019年12月31日 21:59:392019/12/31
收件人 Ruby on Rails: Talk


On Monday, December 30, 2019 at 4:52:46 PM UTC-5, Sampson Crowley wrote:
 Actually I think my problem is in the content_tag in my view I could rewrite it as html but I may as well get this right the rails way Presently the problem is  data-conversation_with_id isn't being passed to the javascript
回复全部
回复作者
转发
0 个新帖子