dom-manipulation

Add line breaks or spaces between elements when using jQuery .append()

非 Y 不嫁゛ 提交于 2021-02-18 19:52:40
问题 I have a jQuery set of elements that I get from my DOM by calling: $(".some-selector"); All my elements are DIVs each in its own line. My DIVs are set CSS (among other things) display: inline-block; which prevents them from rendering as block elements (each in its own line). The problem is that when these DIV are rendered they have spaces between them because there's line break in the document between each element. I'm comfortable with that. I could of course use float:left that would get rid

Knockout components (not) binding on new content

若如初见. 提交于 2021-02-06 08:42:18
问题 Redacted question and example I'm trying to get Knockout components to bind after the initial ko.applyBindings(); so I can add custom elements dynamically. In my original post I referred to loading content by ajax, but my problem occurs when custom elements are added to the DOM using something like jQuery append . Here's an example: $(function() { // Register a simple widget: ko.components.register('like-widget', { template: '<div class="alert alert-info">This is the widget</div>' }); //

how to find the child node element of a div “contenteditable” where the cursor is writing on input event handler

江枫思渺然 提交于 2021-01-28 14:28:00
问题 I am trying to create a custom textarea editor by adding contenteditable as attribute on a div element that the text will be as text element and hashtag will be as span element, but the problem is when i want to add a hashtag between text and hashtag, to do that must to find the current index of child element that the cursor is writing, and then i can use inderBefore method to add this element after this index thanks my html code: <div class="text"> <div #textarea class="textarea"

What exactly updates when the DOM is manipulated

爷,独闯天下 提交于 2021-01-27 06:52:51
问题 I am trying to understand exactly what is updated with the regular DOM after a DOM manipulation. Suppose we have the DOM below and I use javascript to delete the li with the class blue. Does this mean that the browser looks at the parent of class blue (eg: id of list 1) and re-renders that DOM node including all the children (minus class blue) and then repaints the whole page based on any css rules? I would think that would be the process but I wasn't sure and can't find any concrete examples

What exactly updates when the DOM is manipulated

白昼怎懂夜的黑 提交于 2021-01-27 06:51:08
问题 I am trying to understand exactly what is updated with the regular DOM after a DOM manipulation. Suppose we have the DOM below and I use javascript to delete the li with the class blue. Does this mean that the browser looks at the parent of class blue (eg: id of list 1) and re-renders that DOM node including all the children (minus class blue) and then repaints the whole page based on any css rules? I would think that would be the process but I wasn't sure and can't find any concrete examples

Adding event listeners to <li> that are created using javascript

Deadly 提交于 2020-06-26 12:13:32
问题 I am quite new to manipulating elements in the DOM in JS so I am creating a simple to do list to get more comfortable and where I can add items using the input and remove items by clicking on the list item. ALthough this may not be best practice and limitting I am just wanting to use create and remove elements rather than using objects or classes until I get more familar, also using plain/vanilla js so please keep this in mind when answering. I am trying to add a click event which removes the

Why use ViewContainerRef over *ngif?

社会主义新天地 提交于 2020-05-09 18:55:29
问题 I could just do <my-awesome-component *ngIf="ConditionToIncludeComponent"></my-awesome-component> But every document on inserting component in dom dynamically is based on ViewContainerRef. I like what it does. But what makes it so special over *ngif? Just point out pros and cons of both. Please. Thanks! 回答1: TLDR; If you don't know what component will be used in a component template when putting together this template use viewContainerRef . If you do know the component beforehand but it can

Javascript too fast for DOM-manipulation?

五迷三道 提交于 2020-03-06 03:25:34
问题 In Javascript I load some elements via AJAX from a server, and for each data-element I create a <div> that contains another div and an <img> . The inner div contains between 2 and 5 lines of text. I arrange three of this items side by side in a row, then the next three in the next row and so on. But since the texts have different lengths, I want to do some fine-adjustment of the elements within each row. I want the top-edges of all three images to be on the same height. To do this, I do this:

Angular apply class in directive

五迷三道 提交于 2020-01-30 08:36:24
问题 I have a angular directive which will produce bootstrap form-group, looks for $scope.errors for value of ng-model of the directive to show errors.. Example below: My html code: <input type="text" b-input ng-model="data.company.name" label="Company Name" class="form-control"/> and my directive code: app.directive('bInput', function ($compile) { return { restrict: 'EA', replace: true, link: function (scope, element, attrs) { var div = $('<div>', { 'class': 'form-group', 'ng-class': " 'has-error

DOMNodeInserted in the IE

橙三吉。 提交于 2020-01-24 00:55:07
问题 Why doesn't this code work in IE? Please help fix it: jQuery('body').live('DOMNodeInserted',function(e){ var parent = jQuery(e.target).parent(); parent.find("a").css('color','#AA62C6'); parent.find('a').removeAttr('onmousedown'); }); 回答1: This event is not supported in IE. This is added to IE9 but seems to be buggy in the implementation. A solution will be to handle the dom manipulation at the base(The method which is changing the dom) level. function update(){ //do some dom manipulation $