Apply css to Parent

Asked

Viewed 127 times

0

I have an input without borders inside a div and next to the input has a magnifying glass, in this case it is a search field, as far as I know is not possible with css but only with javascript, more suddenly someone can give me an idea, I need when I click on input text to div to have a custom border.

Below I will attach an image of how the component is, note that the outline is a gray div and inside it has an input and an img, when clicking on the input this gray div should be blue.

inserir a descrição da imagem aqui

  • 2

    Show your code and explain what you want to do better. It might be possible without applying css to Parent (which in fact CSS does not).

  • See in the image above, I think you can understand well what I need to do, the idea is to try not to use javascript

1 answer

0

Using angular I created a directive that makes this functionality for my fields and when it is simple fields I get the proper Focus of the input and Seto the edge for it, I believe to be the cleanest possible solution, for those interested follow the code:

(function() {
  'use strict';

  function inputFocus() {
    return {
      restrict: 'A',
      link: function($element) {
        $element.bind("focus", function(event) {
            jQuery($element).parent().addClass('div-focus-input');
        });

        $element.bind("focusout", function (event) {
            jQuery($element).parent().removeClass('div-focus-input');
        });
      }
    };
  }

  angular.module('myApp').directive('inputFocus', inputFocus);

})();
  • I suggest including the angular tag so that the article can be better used.

Browser other questions tagged

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