I’ve got a form on a webpage, but i don’t have access to the HTML or CSS of the page. So any manipulation has to be done with JavascriptJQuery.
And I’m trying to change the styling on some elements before & after the "Company Name" (input) field. I can identifytarget this fieldelement as it has a unique id, and i already have some code which is changing the styling of this element. The id of this element is "parentcustomerid_name".
Using inspection in the browser i get this HTML (the ‘parentcustomerid_name’ element is selected).
The div with the class "input-group" immediately above it (lower tree) i want to add the style of ‘width:100%’.
The div with the class "input-group-btn" below it, i want to add the style of ‘display:none’ (the purpose is to hide the 2 buttons).
I can’t target those element’s by there class as it would effect other fields like "Prefix".
I don’t believe i could use ‘previousSibling’ as it’s on a different tree level.
I don’t believe i could use ‘nextSibling’ as it would return a hidden input field.
(well in testing im having issues)
at the moment this is the code i have – its just disabling the field (so nothing can be entered/selected), as disabling the field removed the border i added it back in, and as disabling the field also removed padding before the text i added that in. Obviously as im disabling the field then i want to remove the buttons on the right hand side as they still function.
$(document).ready(function () {
document.getElementById("parentcustomerid_name").disabled = true;
document.getElementById("parentcustomerid_name").style.padding = "0px 0px 0px 12px";
document.getElementById("parentcustomerid_name").style.border = "1px solid #949494";
}
Any help is greatly appreciated.
2
Answers
Thanks to @Milan Lakhani comments above i got the answer:
this is how the form looks now:
You can query for the closest parent with a particular class:
Or, you can use CSS; although this is still experimental:
Since you don’t have control of the CSS, you can inject a script tag: